0. */ function authenticate_teacher($username, $password) { return ( authenticate($username, $password) && get_user_level($username) > 0 ); } /** * Authenticates administrator. * * Ensures, that level is > 1. */ function authenticate_admin($username, $password) { return ( authenticate($username, $password) && get_user_level($username) > 1 ); } /** * Saves new password. * * Changes the password belonging to $username. * Since VIKO 1.1 SHA1 function is used to encrypt the password. */ function save_password($username, $password) { mysql_query(" UPDATE Users SET password = SHA1('$password') WHERE username='$username' "); } /** * Get the user level number. * * Returns the level number, corresponding to supplied $username. * If username does not exist, returns FALSE. */ function get_user_level($username) { $result = mysql_query(" SELECT level FROM Users WHERE username = '$username' LIMIT 1 "); if ( mysql_num_rows($result) == 1 ) { $user = mysql_fetch_array($result); return $user["level"]; } else { return false; } } // Authenticates the user by applying // custom hashfunction to the $password. // On success returns true. function auth_with_custom_password_function($username, $password, $function) { $result = mysql_query(" SELECT user_id FROM Users WHERE username = '$username' AND password = $function('$password') LIMIT 1 "); return ( mysql_num_rows($result) == 1 ) ? true : false; } // uses OLD_PASSWORD() to authent function auth_with_old_password($username, $password) { return auth_with_custom_password_function($username, $password, "OLD_PASSWORD"); } // uses PASSWORD() to authent function auth_with_password($username, $password) { return auth_with_custom_password_function($username, $password, "PASSWORD"); } // uses SHA1() to authent function auth_with_sha1($username, $password) { return auth_with_custom_password_function($username, $password, "SHA1"); } ?>