$email)); if (!empty($user_results)) { throw new Exception("User with email $email already exists."); } $salt = rand(); $user = new User(null, array( 'email' => $email, 'passwordHash' => sha1($password . $salt), 'passwordSalt' => $salt)); $user->save(); return $user; } public static function login($email, $password) { $user_results = User::get(array("email" => $email)); if (empty($user_results)) { throw new Exception("User with email $email not found."); } $user = $user_results[0]; if (sha1($password . $user->passwordSalt) != $user->passwordHash) { throw new Exception("Wrong password."); } return $user; } public static function restore($session) { $user_results = User::get(array("uid" => $session)); if (empty($user_results)) { throw new Exception("Session with id $session not found."); } return $user_results[0]; } } ?>