Example #1
0
 /**
  * Test login credentials and set the login session value if good
  *
  * @static
  * @param string $email User's email address
  * @param string $password User's password
  * @param boolean $setcookie Optional, if true it will also set a cookie login value for easily restoring the user's login credentials.
  * @return integer See the ERR_LOGIN constants at the beginning of this file for return results.
  * @access public
  */
 public static function Login($email, $password, $setcookie = false)
 {
     $u = User::LoadByEmail($email);
     if (!$u) {
         return ERR_LOGIN_BADUSER;
     }
     if (!$u->testPassword($password)) {
         return ERR_LOGIN_BADPASS;
     }
     $u->handleLogin();
     if ($setcookie) {
         setcookie('user_email', $u['email'], time() + 60 * 60 * 24 * USER_REMEMBERME_EXPIRE, '/');
         setcookie('user_pass', sha1($u['password']), time() + 60 * 60 * 24 * USER_REMEMBERME_EXPIRE, '/');
     }
     return ERR_LOGIN_OK;
 }