Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Deprecate com.nulabinc.zxcvbn.Guess and introduce new interface in com.nulabinc.zxcvbn.guesses #166

Merged
merged 1 commit into from
Sep 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 31 additions & 6 deletions src/main/java/com/nulabinc/zxcvbn/Guess.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,38 @@
import com.nulabinc.zxcvbn.matchers.Match;
import java.util.Calendar;

/**
* Represents a strategy for estimating the number of guesses required to crack a given {@link
* Match}.
*
* <p>Implementations of this interface are expected to evaluate the strength or weakness of a
* matched pattern within a password and return an estimated guess number.
*
* @deprecated This interface is deprecated. Use {@link com.nulabinc.zxcvbn.guesses.Guess} instead.
* @see Match
*/
public interface Guess {

public static final int BRUTEFORCE_CARDINALITY = 10;
public static final int MIN_SUBMATCH_GUESSES_SINGLE_CHAR = 10;
public static final int MIN_SUBMATCH_GUESSES_MULTI_CHAR = 50;
public static final int MIN_YEAR_SPACE = 20;
public static final int REFERENCE_YEAR = Calendar.getInstance().get(Calendar.YEAR);
/** Cardinality used in brute force attacks. */
int BRUTEFORCE_CARDINALITY = 10;

public double exec(Match match);
/** Minimum number of guesses when the sub-match contains a single character. */
int MIN_SUBMATCH_GUESSES_SINGLE_CHAR = 10;

/** Minimum number of guesses when the sub-match contains multiple characters. */
int MIN_SUBMATCH_GUESSES_MULTI_CHAR = 50;

/** The minimum range of years to be considered when evaluating date-based patterns. */
int MIN_YEAR_SPACE = 20;

/** Reference year used for date-based pattern evaluations. */
int REFERENCE_YEAR = Calendar.getInstance().get(Calendar.YEAR);

/**
* Evaluates the given {@link Match} and estimates the number of guesses required to crack it.
*
* @param match the matched pattern to evaluate.
* @return the estimated number of guesses required to crack the given match.
*/
double exec(Match match);
}
1 change: 0 additions & 1 deletion src/main/java/com/nulabinc/zxcvbn/guesses/BaseGuess.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.nulabinc.zxcvbn.guesses;

import com.nulabinc.zxcvbn.Context;
import com.nulabinc.zxcvbn.Guess;

public abstract class BaseGuess implements Guess {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.nulabinc.zxcvbn.guesses;

import com.nulabinc.zxcvbn.Context;
import com.nulabinc.zxcvbn.Guess;
import com.nulabinc.zxcvbn.Pattern;
import com.nulabinc.zxcvbn.Scoring;
import com.nulabinc.zxcvbn.matchers.Match;
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/com/nulabinc/zxcvbn/guesses/Guess.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.nulabinc.zxcvbn.guesses;

import com.nulabinc.zxcvbn.matchers.Match;
import java.util.Calendar;

/**
* Represents a strategy for estimating the number of guesses required to crack a given {@link
* Match}.
*
* <p>Implementations of this interface are expected to evaluate the strength or weakness of a
* matched pattern within a password and return an estimated guess number.
*
* @see Match
*/
public interface Guess {

/** Cardinality used in brute force attacks. */
int BRUTEFORCE_CARDINALITY = 10;

/** Minimum number of guesses when the sub-match contains a single character. */
int MIN_SUBMATCH_GUESSES_SINGLE_CHAR = 10;

/** Minimum number of guesses when the sub-match contains multiple characters. */
int MIN_SUBMATCH_GUESSES_MULTI_CHAR = 50;

/** The minimum range of years to be considered when evaluating date-based patterns. */
int MIN_YEAR_SPACE = 20;

/** Reference year used for date-based pattern evaluations. */
int REFERENCE_YEAR = Calendar.getInstance().get(Calendar.YEAR);

/**
* Evaluates the given {@link Match} and estimates the number of guesses required to crack it.
*
* @param match the matched pattern to evaluate.
* @return the estimated number of guesses required to crack the given match.
*/
double exec(Match match);
}