/**
  * Creates user
  *
  * @param array $array Array of parameters
  * @throws ModelException
  */
 public function create(array $array)
 {
     $user = new User();
     $this->convertDates($array, ['birth_date']);
     $user->populate($array);
     $existingUser = $this->dao->getUserByLogin($user->login);
     if (!is_null($existingUser)) {
         throw new ModelException('This login already exists');
     }
     $passwordManager = new PasswordManager();
     $salt = $passwordManager->getRandomSalt();
     $password = $passwordManager->getHash($array['password'], $salt);
     $user->password = $password;
     $user->salt = $salt;
     $this->dao->save($user);
 }
 /**
  * Makes user authorization
  *
  * @param string $login Login
  * @param string $password Password
  * @param bool|false $remember Remember flag state
  * @throws IncorrectPasswordException
  * @throws LoginNotFoundException
  */
 public function login($login, $password, $remember = false)
 {
     $login = trim($login);
     $user = DaoFactory::getUserDao()->getUserByLogin($login);
     if (!is_null($user)) {
         $psw = new PasswordManager();
         if ($user->getPassword() !== $psw->getHash($password, $user->getSalt())) {
             throw new IncorrectPasswordException('Incorrect password');
         } else {
             $id = $user->getId();
             $this->makeSession($id);
             if ($remember) {
                 $this->makeCookie('field1', $id);
                 $this->makeCookie('field2', $this->getSecretPhrase($id, $login, $password));
             }
         }
     } else {
         throw new LoginNotFoundException('User not found');
     }
 }