<?php 
defined('IN_HS') or exit('Access Denied');

function quescrypt($questionid, $answer)
{
	return $questionid > 0 && $answer != '' ? substr(md5($answer.md5($questionid)), 16, 8) : '';
}

if($action == 'login')
{
	$isadmin = 0;
	if($groupid == 1)
	{
		$isadmin = 1;
		$a = $db->get_one("SELECT grade FROM ".TABLE_ADMIN." WHERE userid=$userid limit 0,1");
		if(!$a || $a['grade'] > 0) $isadmin = 0;
	}
	if($gender==0)	$gender = 2;
	$txt = "time=$PHP_TIME&cookietime=$cookietime&username=$username&password=$password&secques=".quescrypt(1,'hs')."&email=$email&isadmin=$isadmin&regip=$regip&regdate=$regtime";
	$auth = hs_auth($txt, 'ENCODE', $HS['passport_key']);
	$verify = md5('login'.$auth.$forward.$HS['passport_key']);
	$url = $HS['passport_url'].'?action=login&auth='.urlencode($auth).'&forward='.urlencode($forward).'&verify='.$verify;
}
elseif($action == 'logout')
{
	$auth = hs_auth('', 'ENCODE', $HS['passport_key']);
	$verify = md5('logout'.$auth.$forward.$HS['passport_key']);
	$url = $HS['passport_url'].'?action=logout&auth='.urlencode($auth).'&forward='.urlencode($forward).'&verify='.$verify;
}
?>