From 0fe1072985666c58cb624e1e9a52c016348d4cdd Mon Sep 17 00:00:00 2001 From: JustSomeDude2001 <42960562+JustSomeDude2001@users.noreply.github.com> Date: Tue, 11 Feb 2025 12:16:38 +0300 Subject: [PATCH 1/4] Fix compilation errors, declare all required methods and classes --- PasswordLockoutRequirement.java | 23 +++++++++++++++++++++++ PasswordMinimumLength.java | 3 --- PasswordPolicy.java | 3 --- 3 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 PasswordLockoutRequirement.java diff --git a/PasswordLockoutRequirement.java b/PasswordLockoutRequirement.java new file mode 100644 index 0000000..833bb3f --- /dev/null +++ b/PasswordLockoutRequirement.java @@ -0,0 +1,23 @@ +public class PasswordLockoutRequirement extends Requirement { + + @Override + public Checkable.CheckStatus check() { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Unimplemented method 'check'"); + } + + public PasswordLockoutRequirement(String username) { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Unimplemented method 'PasswordLockoutRequirement'"); + } + + public void recordFailedAttempt() { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Unimplemented method 'recordFailedAttempt'"); + } + + public void resetFailedAttempts() { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Unimplemented method 'resetFailedAttempts'"); + } +} 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; From 1a18b547e7bf63a810d76a24e8b251682822d6f5 Mon Sep 17 00:00:00 2001 From: JustSomeDude2001 <42960562+JustSomeDude2001@users.noreply.github.com> Date: Tue, 11 Feb 2025 12:23:20 +0300 Subject: [PATCH 2/4] Implement lockout requirement --- PasswordLockoutRequirement.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/PasswordLockoutRequirement.java b/PasswordLockoutRequirement.java index 833bb3f..ec2523f 100644 --- a/PasswordLockoutRequirement.java +++ b/PasswordLockoutRequirement.java @@ -1,23 +1,25 @@ public class PasswordLockoutRequirement extends Requirement { + private int failedAttempts; + @Override public Checkable.CheckStatus check() { - // TODO Auto-generated method stub - throw new UnsupportedOperationException("Unimplemented method 'check'"); + if (failedAttempts >= 5) { + return CheckStatus.PASS; + } else { + return CheckStatus.FAIL; + } } public PasswordLockoutRequirement(String username) { - // TODO Auto-generated method stub - throw new UnsupportedOperationException("Unimplemented method 'PasswordLockoutRequirement'"); + failedAttempts = 0; } public void recordFailedAttempt() { - // TODO Auto-generated method stub - throw new UnsupportedOperationException("Unimplemented method 'recordFailedAttempt'"); + failedAttempts += 1; } public void resetFailedAttempts() { - // TODO Auto-generated method stub - throw new UnsupportedOperationException("Unimplemented method 'resetFailedAttempts'"); + failedAttempts = 0; } } From b3c48c4df2266488ef9022452f746db21f1d9b4d Mon Sep 17 00:00:00 2001 From: JustSomeDude2001 <42960562+JustSomeDude2001@users.noreply.github.com> Date: Tue, 11 Feb 2025 13:06:55 +0300 Subject: [PATCH 3/4] Update lockout requirement file to fit the format in the project --- PasswordLockoutRequirement.java | 45 +++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/PasswordLockoutRequirement.java b/PasswordLockoutRequirement.java index ec2523f..7194912 100644 --- a/PasswordLockoutRequirement.java +++ b/PasswordLockoutRequirement.java @@ -1,25 +1,44 @@ public class PasswordLockoutRequirement extends Requirement { - - private int failedAttempts; - - @Override - public Checkable.CheckStatus check() { - if (failedAttempts >= 5) { - return CheckStatus.PASS; - } else { - return CheckStatus.FAIL; - } - } + 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) { - failedAttempts = 0; + super("Requirement 2: Failed password attempts lockout Rquirement"); + 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 = 0; + 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 + } } } From 399541c4e043a440b103a12c73f86d0599f94a65 Mon Sep 17 00:00:00 2001 From: JustSomeDude2001 <42960562+JustSomeDude2001@users.noreply.github.com> Date: Tue, 11 Feb 2025 13:39:46 +0300 Subject: [PATCH 4/4] Change requirement statement to match the original repo --- PasswordLockoutRequirement.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PasswordLockoutRequirement.java b/PasswordLockoutRequirement.java index 7194912..a850c25 100644 --- a/PasswordLockoutRequirement.java +++ b/PasswordLockoutRequirement.java @@ -5,7 +5,7 @@ public class PasswordLockoutRequirement extends Requirement { private String username; public PasswordLockoutRequirement(String username) { - super("Requirement 2: Failed password attempts lockout Rquirement"); + 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; }