Location: PHPKode > projects > AnoBBS 3DES encrypted forum and communication repository > anobbs-3des-encrypted-forum-and-communication-repository/progs/xAuth.php
<?PHP
#########################################################################################
## The main authentication function. Returns an array of response hash and userlevel,  ##
## and the users nickname and the next session id. Returns as array with 5 values +		 ##
## the treated xml blob. This is the fastLogin Auth 2.7 with microsessions, a derivate ##
## of the Open Scripted Login Opacity (OSLO). Adapted to xml by Knut Møgster 2008      ##
#########################################################################################

function xauth($susercode, $dhash, $scodesearch, $seedz, $exec, $xcrc, $cxml) {
	global $bbsfiledir,$dlang,$bbslang,$servIp,$servAgent;
	/*
	$susercode : The encrypted code for the user, used in user search | hex
	$dhash : The compare hash | md5
	$scodesearch : The main BBS code | md5
	$seedz : The session seed, renewed each time the user logs in | md5
	$exec : The microsession seed, renewed on each query for data | md5
	$xcrc : The CRC check. Checks wether the user has access to the CP key | hex
	$cxml : The main forum xml blob | xml
	*/
	## Construct the 'query code' for the session
	$usersessionseek = md5($servIp.$servAgent.$seedz);
	## Get the CP key from xml blob
	$acfkey = trim(ret_xmlfield("acforumkey", $cxml));
	## Decrypt the CRC check
	$xfcrc = hexToString($xcrc);
	$xccrc = trim(TripleDES($acfkey,$xfcrc,0,0,$iv,""));
	$crctestx = md5(md5($acfkey));
	$user_sess = retUsersessdata($seedz, $cxml);
	if($user_sess != "none") {
		## Query exists in forum sessions
		## This equals the value $seedz
		$user_sessid = trim(ret_xmlfield("acusersessionid", $user_sess));
		$user_sessauth = trim(ret_xmlfield("acusersessionauth", $user_sess));
		## Check the session auth data
		if($user_sessauth == $usersessionseek) {
			## This is the user session string, it will contain 480 chars
			## The value $exec must be present, else auth fails
			$user_sesstring = trim(ret_xmlfield("acusersesstring", $user_sess));
			$user_row = retUserxdata($susercode, $cxml);
			## User exists in system
			if($user_row != "none") {
				$user_name = trim(ret_xmlfield("acusername", $user_row));
				$xccrss = md5($crctestx."^".md5($user_name));
				if($xccrss == $xccrc) {
					$user_pass = trim(ret_xmlfield("acuserpass", $user_row));
					$ret_s = md5($user_name);
					$user_level = trim(ret_xmlfield("acuserlevel", $user_row));
					$rgarth = substr($user_sesstring, 0, 31);
					## Do user verification, construct response hash
					if($exec == "srq") {
						$cHash = md5("$user_name:$user_pass:$usersessionseek");
						} else {
						$cHash = md5("$user_name:$user_pass:$usersessionseek$exec");
					}
					if($cHash == $dhash) {
						switch($exec) {
						## Session request ##
						case "srq":
							$ir = time();
							$xct = md5($ir) . 
							md5($ir . $seedz) . 
							md5($ir . $seedz . md5("rockababy!")) .
							md5($ir . $seedz . md5("doobeedoobedoo!")) .
							md5($ir . $seedz . md5("beboprules?!")) .
							md5($ir . $seedz . md5("domeyeah!")) .
							md5($ir . $seedz . md5("oah-oah!!")) .
							md5($ir . $seedz . md5("digi-digi-digi..")) .
							md5($ir . $seedz . md5("hoodi-hoodi!")) .
							md5($ir . $seedz . md5("ohyeah!")) .
							md5($ir . $seedz . md5("googlegooglegoogle!")) .
							md5($ir . $seedz . md5("butitsnowornever!")) .
							md5($ir . $seedz . md5("hellno!")) .
							md5($ir . $seedz . md5("hellyes!")) .
							md5($ir . $seedz . md5("well...?"));
							$ns = md5($seedz . $ir);
							$finalgarth = $xct . $ns;
							//$user_sess =  put_xmlfield("acusersession", $user_sess, $susercode);
							$user_sess =  put_xmlfield("acusersesstring", $user_sess, $finalgarth);
							$user_sess =  put_xmlfield("acusersessname", $user_sess, $susercode);
							$user_sess =  put_xmlfield("acusersesstime", $user_sess, time());
							$ret_hash = md5($ret_s . $seedz . $ns);
							$cxml = mergeSession($cxml, $user_sess, $seedz);
							## Return auth for login
							return array($ret_hash, $user_level, $ns, $seedz, "login", $cxml);
						break;
						default:
							if(eregi($exec, trim($user_sesstring))) {
								$ir = microtime();
								$user_sessname = trim(ret_xmlfield("acusersessname", $user_sess));
								## New session seed is created, stored, then set by javascript on load ##
								## On next refresh, that value must equal the hash stored in the file. ##
								$newgarth = substr($user_sesstring, 32);
								$ns = md5($seedz . $ir);
								$finalgarth = $newgarth . $ns;
								$ret_hash = md5($ret_s . $seedz . $ns);
								if($user_sessid == $seedz && $user_sessname == $susercode) {
									$user_sess =  put_xmlfield("acusersesstime", $user_sess, time());
									$user_sess =  put_xmlfield("acusersesstring", $user_sess, $finalgarth);
									$cxml = mergeSession($cxml, $user_sess, $seedz);
									return array($ret_hash, $user_level, $ns, $seedz, "runtime", $cxml);
									} else {
									## The final comparison for runtime mode failed. We return error
									return array("", "", "", "", $bbslang[3], $cxml);
								}
								} else {
								## The microsessions failed. We return error
								return array("", "", "", "", $bbslang[4], $cxml);
							}
						} // End of switch
						} else {
						## Auth by hash comparison fails. We return error
						return array("", "", "", "", $bbslang[5], $cxml);
					}
					} else {
					## The forum CRC check failed, we return error
					return array("", "", "", "", $bbslang[6], $cxml);
				}
				} else {
				## The user row in forum users returns empty. We return error
				return array("", "", "", "", $bbslang[7], $cxml);
			}
			} else {
			## The auth session fails. Return error
			return array("", "", "", "", $bbslang[8], $cxml);
		}
		} else {
		## The userdata session seek returns 'none'. Return error
		return array("", "", "", "", $bbslang[9], $cxml);
	}
}
?>
Return current item: AnoBBS 3DES encrypted forum and communication repository