Is there a way to maintain the user login attempts limit even after page refresh?
login() {
/* Check if user has fewer than 5 failed login attempts */
if (this.failedAttempts < 4) {
this.auth.login(this.credentials).subscribe(() => {
this.router.navigateByUrl('/');
this.alert.success('Welcome! Thanks for logging in!');
}, (err) => {
this.failedAttempts++;
console.error(err);
this.alert.error('Login failed. Invalid email or password.');
});
/*If user reaches 5 failed attempts, reset count after 5 minutes and disable submit button*/
} else if (this.failedAttempts < 4) {
} else {
/* Increment number of lockouts */
this.numLockedOut++;
this.alert.error('Login failed. Invalid email or password. Locked out for ' + (this.numLockedOut * 300000) / 60000 + ' minutes');
this.btnDisable = true;
setTimeout(() => this.failedAttempts = 0, this.numLockedOut * 300000);
setTimeout(() => this.btnDisable = false, this.numLockedOut * 300000);
}
}
Can we use settimeout()
without restarting the timer on page refresh?