diff --git a/PasswordLockoutRequirement.java b/PasswordLockoutRequirement.java new file mode 100644 index 0000000..a850c25 --- /dev/null +++ b/PasswordLockoutRequirement.java @@ -0,0 +1,44 @@ +public class PasswordLockoutRequirement extends Requirement { + private static final int MAX_FAILED_ATTEMPTS = 5; + private static final int STARTING_FAILED_ATTEMPTS = 0; + private Integer failedAttempts; + private String username; + + public PasswordLockoutRequirement(String username) { + super("Requirement 2: The system must lock a user’s account after " + MAX_FAILED_ATTEMPTS + " consecutive failed login attempts."); + this.failedAttempts = STARTING_FAILED_ATTEMPTS; + this.username = username; + } + + // Increment amount of failed attempts + public void recordFailedAttempt() { + failedAttempts += 1; + } + + // Reset amount of failed attempts to zero + public void resetFailedAttempts() { + failedAttempts = STARTING_FAILED_ATTEMPTS; + } + + // Check if the max amount of failed attempts reached + private boolean isMaxFailedAttemptsReached() { + return failedAttempts >= MAX_FAILED_ATTEMPTS; + } + + @Override + public Checkable.CheckStatus check() { + if (username == null || failedAttempts == null) { + return CheckStatus.INCOMPLETE; // return INCOMPLETE if the requirement was not initialized + } + + boolean attemptCountCheck = isMaxFailedAttemptsReached(); + + System.out.println("2: Amount of failed attempts exceeds " + MAX_FAILED_ATTEMPTS + " - " + (attemptCountCheck ? "PASS" : "FAIL")); + + if (attemptCountCheck) { + return CheckStatus.PASS; // Return PASS if the amount of failed attempts exceeds the threshold for pass + } else { + return CheckStatus.FAIL; // Return FAIL if the lockout requirement failed + } + } +} diff --git a/PasswordMinimumLength.java b/PasswordMinimumLength.java index e3262ca..278928f 100644 --- a/PasswordMinimumLength.java +++ b/PasswordMinimumLength.java @@ -1,6 +1,3 @@ - -import rqcode.concepts.Requirement; - public class PasswordMinimumLength extends Requirement { private static final int MIN_LENGTH = 8; private static final int MAX_LENGTH = 64; diff --git a/PasswordPolicy.java b/PasswordPolicy.java index 251ba3b..d257ee1 100644 --- a/PasswordPolicy.java +++ b/PasswordPolicy.java @@ -1,6 +1,3 @@ -package rqcode.tutorial.tutorial_new; -import rqcode.concepts.CombinedRequirements; -import rqcode.concepts.Requirement; import java.util.Arrays; import java.util.List;