Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions PasswordLockoutRequirement.java
Original file line number Diff line number Diff line change
@@ -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
}
}
}
3 changes: 0 additions & 3 deletions PasswordMinimumLength.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
3 changes: 0 additions & 3 deletions PasswordPolicy.java
Original file line number Diff line number Diff line change
@@ -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;

Expand Down