Determine if the given token is a valid TwoFactor Backup code.

@param \Rinvex\Auth\Contracts\AuthenticatableTwoFactorContract $user
@param int                                                     $token

@return bool
964593
protected function isValidTwoFactorBackup(AuthenticatableTwoFactorContract $user, int $token): bool
    {
        $backup = array_get($user->getTwoFactor(), 'totp.backup', []);
        $result = mb_strlen($token) === 10 && in_array($token, $backup);
        ! $result || $this->invalidateTwoFactorBackup($user, $token);

        return $result;
    }
350430
public function isValidToken($src, $token)
    {
        $img_token = $this->getToken($src);
        if ($img_token === null) {
            return false;
        }

        if (!hash_equals($img_token, $token)) {
            \Yii::warning("Invalid token", __METHOD__);
            return false;
        }

        return true;
    }
1005641
public function validateDigest(WsseUserToken $wsseToken, UserInterface $user)
    {
        $created = $wsseToken->created;
        $nonce = $wsseToken->nonce;
        $digest = $wsseToken->digest;
        $secret = $user->getPassword();

        // Check created time is not too far in the future (leaves 5 minutes margin)
        if (strtotime($created) > (time() + 300)) {
            throw new WsseAuthenticationException(sprintf(
                'Token created date cannot be in future (%d seconds in the future).',
                time() - strtotime($created)
            ));
        }

        // Expire timestamp after 5 minutes
        if (strtotime($created) < (time() - 300)) {
            throw new WsseAuthenticationException(sprintf(
                'Token created date has expired its 300 seconds of validity (%d seconds).',
                strtotime($created) - time()
            ));
        }

        // Validate that the nonce is *not* used in the last 10 minutes
        // if it has, this could be a replay attack
        if (file_exists($this->cacheDir.'/'.$nonce) && file_get_contents($this->cacheDir.'/'.$nonce) + 600 > time()) {
            throw new NonceExpiredException('Previously used nonce detected.');
        }
        // If cache directory does not exist we create it
        if (!is_dir($this->cacheDir)) {
            mkdir($this->cacheDir, 0777, true);
        }

        file_put_contents($this->cacheDir.'/'.$nonce, time());

        // Validate Secret
        $expected = base64_encode(sha1(base64_decode($nonce).$created.$secret, true));

        if (!StringUtils::equals($expected, $digest)) {
            throw new WsseAuthenticationException('Token digest is not valid.');
        }

        return true;
    }
243863
@Restricted(NoExternalUse.class)
    public boolean hasFreshToken(@Nonnull User user, @Nullable ApiTokenProperty.TokenInfoAndStats legacyStats) {
        if (legacyStats == null) {
            return false;
        }
        
        ApiTokenProperty apiTokenProperty = user.getProperty(ApiTokenProperty.class);
        
        return apiTokenProperty.getTokenList().stream()
                .filter(token -> !token.isLegacy)
                .anyMatch(token -> {
                    Date creationDate = token.creationDate;
                    Date lastUseDate = legacyStats.lastUseDate;
                    if (lastUseDate == null) {
                        lastUseDate = legacyStats.creationDate;
                    }
                    return creationDate != null && lastUseDate != null && creationDate.after(lastUseDate);
                });
    }
251078
private function hasOpenEmailValidation(User $user)
    {
        $ts = $user->email_verification_token_timestamp;
        if (!empty($ts) && (time() - $this->module->emailVerificationTokenExpirationTime) <= $ts) {
            return true;
        }
        
        return false;
    }
1184848
public function activateUser(string $token)
	{
		$user = $this->userRepository->getByActionToken($token);

		if($user === false)
		{
			return false;
		}

		$user->activate();

		$user->generateActionToken();

		$user->save();

		return $user;
	}
1158563
public static function existsValidToken($token_id, $user_id)
    {
        if (class_exists('\Illuminate\Support\Facades\DB')) {
            return (bool) \Illuminate\Support\Facades\DB::table('oauth_access_tokens')
                ->where('id', $token_id)
                ->where('user_id', $user_id)
                ->where('expires_at', '>=', date('Y-m-d H:i:s'))
                ->get();
        } else {
            return false;
        }
    }
519724
protected function invalidateTwoFactorBackup(AuthenticatableTwoFactorContract $user, int $token): void
    {
        $settings = $user->getTwoFactor();
        $backup = array_get($settings, 'totp.backup');

        unset($backup[array_search($token, $backup)]);

        array_set($settings, 'totp.backup', $backup);

        // Update TwoFactor OTP backup codes
        $user->fill(['two_factor' => $settings])->forceSave();
    }
6298
public static function isTokenValid(string $token): bool
    {
        if (!static::hasTokenStored()) {
            return false;
        }

        $storedToken = static::getStoredToken();
        return $storedToken->getToken() === $token;
    }
161505
public function sendRecoveryMessage($user, $token)
    {
        $mailVars = [
            '{token}' => $token->url
        ];

        /**
         * @var $mailTemplate Template
         */
        $mailTemplate = \Yii::$app->get('emailTemplates')
            ->getTemplate('recovery', Language::getCurrent()->id);
        $mailTemplate->parseSubject($mailVars);
        $mailTemplate->parseBody($mailVars);

        return \Yii::$app->shopMailer->compose('mail-body', ['bodyContent' => $mailTemplate->getBody()])
            ->setFrom([\Yii::$app->shopMailer->transport->getUsername() => \Yii::$app->name ?? Url::to(['/'], true)])
            ->setTo($user->email)
            ->setSubject($mailTemplate->getSubject())
            ->send();
    }
907841
protected function sendVerifyEmailNotification($user, string $token) : array
  {
    return Notification::make(new MustVerifyEmail($user->email, $token));
  }
197529
public function updateRememberToken(UserContract $user, $token)
    {
        $user->setRememberToken($token);

        $timestamps = $user->timestamps;

        $user->timestamps = false;

        $user->save();

        $user->timestamps = $timestamps;
    }
933365
public function exists(Contracts\RequiresEmailVerification $user, $token)
    {
        $email = $user->getEmailForVerification();

        $token = (array) $this->getTable()->where('email', $email)->where('token', $token)->first();

        return $token && !$this->tokenExpired($token);
    }
187975
public function verify(CanVerifyEmailContract $user, $token)
    {
        // If the responses from the validate method is not a user instance, we will
        // assume that it is a redirect and simply return it from this method and
        // the user is properly redirected having an error message on the post.
        $user = $this->validateVerification($user, $token);

        if (! $user instanceof CanVerifyEmailContract) {
            return $user;
        }

        $this->tokens->delete($token);

        $user->setVerified(true);

        $user->save();

        return VerifyEmailBrokerContract::EMAIL_VERIFIED;
    }
703952
public static function isValid($token) {
        // Get configuration
        $expiration = Config::get('security.anti_csrf.expiration', 18000);
        // Compute for token availablity
        $computed = microtime(true) - (double)Text::unlock($token, self::getKey());
        
        return $computed <= $expiration;
    }
1036431
public function isApiSignatureValid(BBUserToken $token, $signaturePresented)
   {
       return StringUtils::equals($this->createSignature($token), $signaturePresented);
   }
1050707
public function validateCredentials(UserContract $user, array $credentials): bool
    {
        $plain = $credentials['password'];
        $hashed = $user->getAuthPassword();

        if (\strlen($hashed) === 0) {
            return false;
        }

        return \password_verify($plain, $hashed) || $this->hasher->check($plain, $hashed);
    }