diff --git a/PasswordLockoutRequirement.java b/PasswordLockoutRequirement.java new file mode 100644 index 0000000..e07000b --- /dev/null +++ b/PasswordLockoutRequirement.java @@ -0,0 +1,37 @@ +public class PasswordLockoutRequirement extends Requirement { + private static final int FAILED_MAX = 5; + private static final int BEFORE_FAILING = 0; + private Integer failedAttempts; + private String uname; + + public PasswordLockoutRequirement(String uname) { + super("Requirement 2: System must lock account after " + FAILED_MAX + " failed attempts."); + this.failedAttempts = BEFORE_FAILING; + this.uname = uname; + } + + public void recordFailedAttempt() { + failedAttempts += 1; + } + + public void resetFailedAttempts() { + failedAttempts = BEFORE_FAILING; + } + + private boolean isMaxFailedAttemptsReached() { + return failedAttempts >= FAILED_MAX; + } + + @Override + public Checkable.CheckStatus check() { + if (uname == null || failedAttempts == null) { + return CheckStatus.INCOMPLETE; + } + + boolean failedAttemptsCheck = isMaxFailedAttemptsReached(); + + System.out.println("2: Amount of failed attempts exceeds " + FAILED_MAX + " - " + (failedAttemptsCheck ? "PASS" : "FAIL")); + + return failedAttemptsCheck ? CheckStatus.PASS : CheckStatus.FAIL; + } +} \ No newline at end of file diff --git a/PasswordMinimumLength.java b/PasswordMinimumLength.java index e3262ca..efe407d 100644 --- a/PasswordMinimumLength.java +++ b/PasswordMinimumLength.java @@ -1,6 +1,4 @@ -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;