/**
  * {@inheritdoc}
  */
 public function issueToken(AuthenticatedUserInterface $user, array $credentials = [], DateTimeInterface $expires_at = null)
 {
     $token_id = isset($this->tokens[$user->getEmail()]) ? $this->tokens[$user->getEmail()] : sha1(time());
     $token = new Token($token_id, $user->getUsername(), $expires_at);
     if (!empty($credentials['extra_attribute'])) {
         $token->setExtraAttribute($credentials['extra_attribute']);
     }
     return $token;
 }
 /**
  * @param AuthenticatedUserInterface|null $user
  * @param string                          $password
  */
 private function verifyUser(AuthenticatedUserInterface $user = null, $password)
 {
     if (!$user) {
         throw new UserNotFoundException();
     }
     if (!$user->isValidPassword($password)) {
         throw new InvalidPasswordException();
     }
     if (!$user->canAuthenticate()) {
         throw new UserNotFoundException();
     }
 }
 /**
  * Create a new session.
  *
  * @param  AuthenticatedUserInterface $user
  * @param  array                      $credentials
  * @param  DateTimeInterface|null     $expires_at
  * @return SessionInterface
  */
 public function createSession(AuthenticatedUserInterface $user, array $credentials = [], DateTimeInterface $expires_at = null)
 {
     /** @var Session $session */
     foreach ($this->sessions as $session) {
         if ($session->getUserId() === $user->getEmail()) {
             return $session;
         }
     }
     $session = new Session(sha1(time()), $user->getUsername(), $expires_at);
     if (!empty($credentials['remember'])) {
         $session->setIsExtendedSession(true);
     }
     return $session;
 }