Changeset 274 for Dev/branches/rest-dojo-ui/server/classes/Auth.php
- Timestamp:
- 02/20/12 16:27:19 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/branches/rest-dojo-ui/server/classes/Auth.php
r256 r274 5 5 class Auth { 6 6 7 public static function login($username, $password) { 8 $user_results = User::get(array("name" => $username)); 9 if (!empty($user_results)) { 10 $user = $user_results[0]; 11 if (sha1($password) == $user->password) { 12 return $user; 13 } 7 public static function register($email, $password) { 8 $user_results = User::get(array("email" => $email)); 9 if ( !empty($user_results) ) { 10 throw new Exception("User with email $email already exists."); 14 11 } 15 return false; 12 $salt = rand(); 13 $user = new User(null,$email,sha1($password.$salt),$salt); 14 $user->save(); 15 return $user; 16 } 17 18 public static function login($email, $password) { 19 $user_results = User::get(array("email" => $email)); 20 if (empty($user_results)) { 21 throw new Exception("User with email $email not found."); 22 } 23 $user = $user_results[0]; 24 if (sha1($password.$user->passwordSalt) != $user->passwordHash) { 25 throw new Exception("Wrong password."); 26 } 27 return $user; 16 28 } 17 29 18 30 public static function restore($session) { 19 31 $user_results = User::get(array("uid" => $session)); 20 if ( !empty($user_results)) {21 return $user_results[0];32 if (empty($user_results)) { 33 throw new Exception("Session with id $session not found."); 22 34 } 23 return false;35 return $user_results[0]; 24 36 } 25 37
Note: See TracChangeset
for help on using the changeset viewer.