/**
  * Loggt einen User ein
  *
  * @param string $username
  * @param string $password
  * @param bool $rememberMe
  * @throws Users\Exception\LoginFailedException
  * @throws Users\Exception\UserAccountLockedException
  */
 public function login($username, $password, $rememberMe)
 {
     $user = $this->userRepository->getOneByNickname($username);
     if (!empty($user)) {
         // The user account has been locked
         if ($user['login_errors'] >= 3) {
             throw new Users\Exception\UserAccountLockedException();
         }
         if ($this->userHasOldPassword($password, $user)) {
             $user = $this->migratePasswordHashToSha512($user['id'], $password);
         }
         if ($user['pwd'] === $this->secureHelper->generateSaltedPassword($user['pwd_salt'], $password, 'sha512')) {
             if ($user['login_errors'] > 0) {
                 $this->userRepository->update(['login_errors' => 0], (int) $user['id']);
             }
             if ($rememberMe === true) {
                 $token = $this->generateRememberMeToken($user);
                 $this->saveRememberMeToken($user['id'], $token);
                 $this->response->headers->setCookie($this->setRememberMeCookie($user['id'], $token));
             }
             $this->sessionHandler->secureSession();
             $this->authenticate($user);
             $this->setSessionValues();
             return;
         } elseif ($this->saveFailedLoginAttempts($user) === 3) {
             throw new Users\Exception\UserAccountLockedException();
         }
     }
     throw new Users\Exception\LoginFailedException();
 }
Example #2
0
 /**
  * @param string $nickNameOrEmail
  * @return array
  */
 protected function fetchUserByFormFieldValue($nickNameOrEmail)
 {
     if ($this->get('core.validation.validation_rules.email_validation_rule')->isValid($nickNameOrEmail) === true && $this->userRepository->resultExistsByEmail($nickNameOrEmail) === true) {
         $user = $this->userRepository->getOneByEmail($nickNameOrEmail);
     } else {
         $user = $this->userRepository->getOneByNickname($nickNameOrEmail);
     }
     return $user;
 }