예제 #1
0
 /**
  * Attempts to register
  * @param  UserCredentials $uc
  * @return boolean
  * 
  */
 public function doRegister(UserCredentials $uc)
 {
     if ($uc->getName() == "") {
         return false;
     } else {
         if ($uc->getPassword() == "") {
             return false;
         } else {
             if (strlen($uc->getName()) < 3) {
                 return false;
             } else {
                 if (strlen($uc->getPassword()) < 6) {
                     return false;
                 } else {
                     if (strcmp($uc->getPassword(), $uc->getTempPassword()) !== 0) {
                         return false;
                     } else {
                         if ($this->usernameExists($uc->getName())) {
                             return false;
                         } else {
                             if (preg_match('/[^a-zA-Z0-9]+/', $uc->getName(), $matches)) {
                                 return false;
                             } else {
                                 $this->registerUser($uc->getName(), $uc->getPassword());
                                 $this->message = "Registered new user.";
                                 return true;
                             }
                         }
                     }
                 }
             }
         }
     }
     return false;
 }
예제 #2
0
 /**
  * Attempts to authenticate
  * @param  UserCredentials $uc
  * @return boolean
  */
 public function doLogin(UserCredentials $uc)
 {
     $this->matchingPassword = $this->rcDAL->load($uc->getName());
     $loginByUsernameAndPassword = \Settings::USERNAME === $uc->getName() && \Settings::PASSWORD === $uc->getPassword() || $this->matchingPassword != "" && password_verify($uc->getPassword(), $this->matchingPassword);
     if ($loginByUsernameAndPassword) {
         $user = new LoggedInUser($uc);
         $_SESSION[self::$sessionUserLocation] = $user;
         return true;
     }
     return false;
 }
예제 #3
0
 /**
  * Attempts to authenticate
  * @param  UserCredentials $uc
  * @return boolean
  */
 public function doLogin(UserCredentials $uc)
 {
     $this->tempCredentials = $this->tempDAL->load($uc->getName());
     $loginByUsernameAndPassword = \Settings::USERNAME === $uc->getName() && \Settings::PASSWORD === $uc->getPassword();
     $loginByUsernameAndPasswordRegistered = $this->checkRegistration($uc->getName(), $uc->getPassword());
     $loginByTemporaryCredentials = $this->tempCredentials != null && $this->tempCredentials->isValid($uc->getTempPassword());
     if ($loginByUsernameAndPassword || $loginByTemporaryCredentials || $loginByUsernameAndPasswordRegistered) {
         $user = new LoggedInUser($uc);
         $_SESSION[self::$sessionUserLocation] = $user;
         return true;
     }
     return false;
 }
예제 #4
0
 /**
  * Attempts to authenticate
  * @param  UserCredentials $uc
  * @return boolean
  */
 public function doLogin(UserCredentials $uc)
 {
     $this->tempCredentials = $this->tempDAL->load($uc->getName());
     $password = $this->userDAL->load($uc->getName());
     $loginByUsernameAndPassword = $uc->getName() !== null && $password === $uc->getPassword();
     $loginByTemporaryCredentials = $this->tempCredentials != null && $this->tempCredentials->isValid($uc->getTempPassword());
     $loginAsAdmin = $uc->getName() === Settings::USERNAME && $uc->getPassword() === Settings::PASSWORD;
     if ($loginAsAdmin || $loginByUsernameAndPassword || $loginByTemporaryCredentials) {
         $user = new LoggedInUser($uc);
         $_SESSION[self::$sessionUserLocation] = $user;
         return true;
     }
     return false;
 }
예제 #5
0
 /**
  * Registrates the current user in the database table
  * @param active user name
  * @return boolean
  */
 public function registerName(UserCredentials $userCredentials)
 {
     $name = $userCredentials->getUsername();
     $password = $userCredentials->getPassword();
     $this->dal->insertUser($name, $password);
     return true;
 }
예제 #6
0
 public function tryLoginUser(UserCredentials $toLogin)
 {
     $registered = $this->userDAL->getUserByName($toLogin->getUsername());
     $tempPassword = $this->tempDAL->getTempPassword($toLogin->getUsername());
     $loginByPostCredentials = password_verify($toLogin->getPassword(), $registered->getPassword());
     $loginByCookies = $tempPassword != "" && $tempPassword === $toLogin->getCookiePassword();
     if (!$loginByPostCredentials && !$loginByCookies) {
         throw new \WrongCredentialsException("Wrong credentials");
     }
     $this->loginUser($toLogin);
 }
예제 #7
0
 public function tryRegister(UserCredentials $uc, &$user)
 {
     $this->userName = $uc->getUserName();
     $this->password = $uc->getPassword();
     $user = new User($this->userName, $this->password);
     if (!User::checkIfUserExists($this->userName)) {
         User::AddUser($user);
         $this->validRegister = true;
         return true;
     } else {
         return false;
     }
 }
 /**
  * Attempts to authenticate
  * @param  UserCredentials $uc
  * @return boolean
  */
 public function doLogin(UserCredentials $uc)
 {
     $this->tempCredentials = $this->tempDAL->load($uc->getName());
     $validUser = $this->dal->getUserCredentials($uc->getName());
     //		$loginByUsernameAndPassword = \Settings::USERNAME === $uc->getName() && \Settings::PASSWORD === $uc->getPassword();
     $loginByUsernameAndPassword = $validUser->getUsername() === $uc->getName() && password_verify($uc->getPassword(), $validUser->getPassword());
     $loginByTemporaryCredentials = $this->tempCredentials != null && $this->tempCredentials->isValid($uc->getTempPassword());
     if ($loginByUsernameAndPassword || $loginByTemporaryCredentials) {
         $user = new LoggedInUser($uc);
         $_SESSION[$this->sessionUserLocation] = $user;
         return true;
     }
     return false;
 }
예제 #9
0
 /**
  * Attempts to authenticate
  * @param  UserCredentials $uc
  * @return boolean
  */
 public function doLogin(UserCredentials $uc, \model\RegisterModel $regModel)
 {
     $this->tempCredentials = $this->tempDAL->load($uc->getName());
     $loginByUsernameAndPassword = false;
     $userData = $regModel->getUser($uc->getName());
     if ($userData) {
         $userDataSep = explode("::", $userData);
         $pwDecrypt = password_verify(trim($uc->getPassword()), trim($userDataSep[1]));
         $loginByUsernameAndPassword = strcmp($uc->getName(), $userDataSep[0]) == 0 && $pwDecrypt;
         // $loginByUsernameAndPassword = (strcmp($uc->getName(), $userDataSep[0]) == 0) && (strcmp(trim($uc->getPassword()), trim($userDataSep[1])) == 0);
     } else {
         $loginByUsernameAndPassword = false;
     }
     $loginByTemporaryCredentials = $this->tempCredentials != null && $this->tempCredentials->isValid($uc->getTempPassword());
     if ($loginByUsernameAndPassword || $loginByTemporaryCredentials) {
         $user = new LoggedInUser($uc);
         $_SESSION[self::$sessionUserLocation] = $user;
         return true;
     }
     return false;
 }
예제 #10
0
 private function saveUser(UserCredentials $credentials)
 {
     $this->DAL->saveUserCredentials($credentials->getUsername(), $credentials->getPassword());
 }