'AuthUserMySQL', with 'mysql' => 'AuthUserDatabase', */ # # Release History # =============== # # v.0.1 July, 2005 - Private release # v.0.2 May 31, 3006 - Semi-public release. # v.1.0 ---- -, 2006 - Initial public release. # * I am trying to implement multiple-table support # * Cleaning up for easier use on various sites. # v.1.0.01 July 25, 2006 by akc - fixed 3 typos # v.1.0.02 Aug 03, 2006 by akc - working at last if (!$AuthUser) return; SDV($AUDBaseEncryption, 'md5'); SDV($AUDBaseDBase, array( 'host' => 'localhost', 'db' => '', 'user' => '', 'password' => '', ) ); SDV($AUDBaseTable, array( 'table' => 'users', 'userfield' => 'username', 'pwfield' => 'password', ) ); SDV($AUDBaseConditional, ''); SDV($AUDBaseEngine, 'mysql'); #$AuthForm =<< # # # # # # # # #
Name:
Password:
# #
# # # #AUTHFORM; #$AuthPromptFmt = array(&$PageStartFmt, $AuthForm, &$PageEndFmt); function AuthUserDBaseError($t, $e) { $msg = array( 'query' => "Could not successfully run query (\$ask) from DB: ", 'dbase' => "Unable to select database \$AUDBaseDBase[db]: ", 'conn' => "Could not connect: ", ); die($msg[$t] . $e); } function AuthUserPgSQL($ask) { global $AUDBaseDBase; pg_connect( "host=$AUDBaseDBase[host] " . "dbname=$AUDBaseDBase[db] " . "user=$AUDBaseDBase[user] " . "password=$AUDBaseDBase[password]" ) or AuthUserDBaseError('conn',pg_last_error()); $result = pg_fetch_assoc($ask) or AuthUserDBaseError('query',mysql_error()); return ($result['authorized']); } function AuthUserMySQL($ask) { global $AUDBaseDBase; mysql_connect( $AUDBaseDBase['host'], $AUDBaseDBase['user'], $AUDBaseDBase['password'] ) or AuthUserDBaseError('conn',mysql_error()); @mysql_select_db($AUDBaseDBase['db']) or AuthUserDBaseError('dbase',mysql_error()); $result = mysql_query($ask) or AuthUserDBaseError('query',mysql_error()); $row = mysql_fetch_array($result); return ($row['AUTHORIZED']) ? true : false; } function AuthUserDatabase($pagename, $id, $pw, $pwlist) { global $AUDBaseTable, $AUDBaseEncryption, $AUDBaseConditional, $AUDBaseEngine; #----------------------------------- # Encryption Switch switch($AuthDBaseEncription) { case 'md5' : $pw = md5($pw); break; case 'sha1' : $pw = sha1($pw); break; default : $pw = md5($pw); break; } #----------------------------------- # Query Preparation $u = $AUDBaseTable['userfield']; $p = $AUDBaseTable['pwfield']; $t = $AUDBaseTable['table']; $w = $AUDBaseConditional; $n = $AUDBaseEncryption; $ask = "SELECT count(*) AS AUTHORIZED FROM $t WHERE $u='$id' AND $p='$pw' $w;"; #----------------------------------- # Database Switch switch($AUDBaseEngine) { case 'mysql' : $answer = AuthUserMySQL($ask); break; case 'pgsql' : $answer = AuthUserPgSQL($ask); break; default : $answer = AuthUserMySQL($ask); break; } return ($answer) ? true : false; return false; }