src/mako/gatekeeper/entities/user/User.php
public function throttle(int $maxLoginAttempts, int $lockTime, bool $autoSave = true): bool
	{
		$now = Time::now();

		// Reset the failed attempt count if the last failed attempt was more than $lockTime seconds ago

		if($this->last_fail_at !== null)
		{
			if(($now->getTimestamp() - $this->last_fail_at->getTimestamp()) > $lockTime)
			{
				$this->failed_attempts = 0;
			}
		}

		// Increment the failed attempt count and update the last fail time

		$this->failed_attempts++;

		$this->last_fail_at = $now;

		// Lock the account for $lockTime seconds if we have exeeded the maximum number of login attempts

		if($this->failed_attempts >= $maxLoginAttempts)
		{
			$this->locked_until = (clone $now)->forward($lockTime);
		}

		// Save the changes to the user if autosave is enabled

		return $autoSave ? $this->save() : true;
	}
public function throttle(int $maxLoginAttempts, int $lockTime, bool $autoSave = true): bool
	{
		$now = Time::now();

		// Reset the failed attempt count if the last failed attempt was more than $lockTime seconds ago

		if($this->last_fail_at !== null)
		{
			if(($now->getTimestamp() - $this->last_fail_at->getTimestamp()) > $lockTime)
			{
				$this->failed_attempts = 0;
			}
		}

		// Increment the failed attempt count and update the last fail time

		$this->failed_attempts++;

		$this->last_fail_at = $now;

		// Lock the account for $lockTime seconds if we have exeeded the maximum number of login attempts

		if($this->failed_attempts >= $maxLoginAttempts)
		{
			$this->locked_until = (clone $now)->forward($lockTime);
		}

		// Save the changes to the user if autosave is enabled

		return $autoSave ? $this->save() : true;
	}
public function throttle ( int $ maxLoginAttempts , int $ lockTime , bool $ autoSave = true ) : bool { $ now = Time :: now ( ) ; // Reset the failed attempt count if the last failed attempt was more than $lockTime seconds ago if ( $ this -> last_fail_at !== null ) { if ( ( $ now -> getTimestamp ( ) - $ this -> last_fail_at -> getTimestamp ( ) ) > $ lockTime ) { $ this -> failed_attempts = 0 ; } } // Increment the failed attempt count and update the last fail time $ this -> failed_attempts ++ ; $ this -> last_fail_at = $ now ; // Lock the account for $lockTime seconds if we have exeeded the maximum number of login attempts if ( $ this -> failed_attempts >= $ maxLoginAttempts ) { $ this -> locked_until = ( clone $ now ) -> forward ( $ lockTime ) ; } // Save the changes to the user if autosave is enabled return $ autoSave ? $ this -> save ( ) : true ; }
Throttles login attempts.

@param  int  $maxLoginAttempts Maximum number of failed login attempts
@param  int  $lockTime         Number of seconds for which the account gets locked after reaching the maximum number of login attempts
@param  bool $autoSave         Autosave changes?
@return bool
Throttles login attempts .