Skip to content

Commit

Permalink
Merge pull request #166 from nulab/move-guess-interface
Browse files Browse the repository at this point in the history
refactor: Deprecate com.nulabinc.zxcvbn.Guess and introduce new interface in com.nulabinc.zxcvbn.guesses
  • Loading branch information
vvatanabe authored Sep 3, 2023
2 parents 75fd7ce + 65a93c9 commit dcaf9da
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 8 deletions.
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);
}

0 comments on commit dcaf9da

Please sign in to comment.