From b2e515e0ec05dcaa2991fc1cb8e2ef225f63c349 Mon Sep 17 00:00:00 2001 From: Marina Ivanova Date: Wed, 12 Feb 2025 13:46:46 +0000 Subject: [PATCH] add password lockout requirement --- PasswordLockoutRequirement.java | 60 +++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 PasswordLockoutRequirement.java diff --git a/PasswordLockoutRequirement.java b/PasswordLockoutRequirement.java new file mode 100644 index 0000000..91839f8 --- /dev/null +++ b/PasswordLockoutRequirement.java @@ -0,0 +1,60 @@ +public class PasswordLockoutRequirement extends Requirement { + private String username; + private int MAX_ATTEMPTS_COUNT = 5; + private int attemptsCount; + private boolean isLocked; + + public PasswordLockoutRequirement(String username) { + super("Requirement 3: Password Lockout Requirement"); + this.username = username; + this.attemptsCount = 0; + this.isLocked = false; + } + + + @Override + public CheckStatus check() { + if (this.isLocked) { + System.out.println("Account is locked."); + } else { + System.out.println("Account is unlocked."); + } + return (((this.attemptsCount==MAX_ATTEMPTS_COUNT) && this.isLocked) || ((this.attemptsCount= MAX_ATTEMPTS_COUNT) { + this.lockAccount(); + } + } else { + this.lockAccount(); + } + } + + public void recordSuccessfullAttempt() { + if (!this.isLocked) { + System.out.println("Login Attempt Status: PASS Failed Attempts Count: "+this.attemptsCount); + resetFailedAttempts(); + } else { + this.lockAccount(); + } + } + + private void lockAccount() { + this.isLocked = true; + System.out.println("FATAL: Account is locked! Please, reset your password."); + } + + public boolean resetFailedAttempts() { + this.attemptsCount = 0; + this.isLocked = false; + System.out.println("Failed attempt count was reset! Failed Attempts Count: "+this.attemptsCount); + return true; + } + + +} \ No newline at end of file