Ejemplo n.º 1
0
 /**
  * Login user
  * 
  * @param string $user
  * @param string $password
  * @param boolean $remember
  * @return boolean
  */
 public function login($user, $password, $remember)
 {
     $output = false;
     if (!empty($user) and !empty($password) and preg_match('/[\\w\\d]+/', $password)) {
         $password = $this->generatePasswordHash($password);
         $userData = $this->mUsers->getByNick($user);
         if (empty($userData)) {
             $userData = $this->mUsers->getByEmail($user);
         }
         if (!empty($userData) and $userData['password'] == $password and $userData['cisStatus'] == Users::STATUS_ACTIVE) {
             $_SESSION[self::SESSION_KEY] = array();
             session_regenerate_id();
             $_SESSION[self::SESSION_KEY] = array('idUser' => $userData['idUser'], 'nick' => $userData['nick'], 'time' => time());
             $sessionHash = '';
             if ($remember) {
                 $sessionHash = md5($this->config->get('salt') . $_SERVER['REMOTE_ADDR'] . session_id() . $userData['nick']);
                 setcookie('login', $sessionHash, strtotime('+1 month'), '/');
             } else {
                 setcookie('login', '', time() - 3600, '/');
             }
             $this->updateSession($_SERVER['REMOTE_ADDR'] . ' ' . $sessionHash);
             $output = true;
         }
     }
     return $output;
 }