Ejemplo n.º 1
0
 /**
  * @param string $username
  * @throws \Exception
  */
 public function create($username)
 {
     if (false === ($user = $this->users->findOneByUsername($username))) {
         throw new \Exception(sprintf('User "%s" not found', $username));
     }
     $user->setLastLoginTime(date('Y-m-d H:i:s'))->save();
     $this->userSessions->create(['hash' => $this->session->getHash(), 'user_id' => $user->getId(), 'remote_address' => $this->session->getAddress(), 'start_time' => $user->getLastLoginTime()]);
 }
Ejemplo n.º 2
0
 /**
  * Validate login credentials
  *
  * @param string $username
  * @param string $password
  * @return bool
  */
 public function validate($username, $password)
 {
     $success = false;
     $this->users->select([['column' => 'username', 'value' => $username], ['column' => 'deleted', 'value' => false]]);
     if (count($this->users) === 1) {
         /** @var \Core\Persistence\Entity\User $user */
         $user = $this->users->current();
         if ($password === hash('SHA512', $user->getPassword() . $this->session->getHash())) {
             $success = true;
         }
     }
     return $success;
 }