Package xyz.jorgecastro.passwordcritic
Class PasswordCritic
java.lang.Object
com.nulabinc.zxcvbn.Zxcvbn
xyz.jorgecastro.passwordcritic.PasswordCritic
public class PasswordCritic
extends com.nulabinc.zxcvbn.Zxcvbn
The PasswordCritic class provides various methods to assess password strength and present the results in a
user-friendly format.
It extends Zxcvbn.
- See Also:
-
WipeableStringStrengthHashFunctionRetrofit
-
Constructor Summary
ConstructorsConstructorDescriptionPasswordCritic(char[] password) Construct an instance ofPasswordCriticready to operate on the given password. -
Method Summary
Modifier and TypeMethodDescriptioncritique()Provide an assessment of this instance's associated password using all the available information.doubleCallsgetCalcTime(Strength)and passes theStrengthobject derived from this instance's associated password.static doublegetCalcTime(com.nulabinc.zxcvbn.Strength strength) Return a double representing the time (in seconds) that it took to calculate a password'sStrength.CallsgetCrackTimesEstimate(Strength)and passes theStrengthobject derived from this instance's associated password.static StringgetCrackTimesEstimate(com.nulabinc.zxcvbn.Strength strength) Return a nicely formattedStringwith estimates on how long it'd take to crack a password with thisStrength.CallsparseFeedback(Feedback)and passes theFeedbackobject generated from theStrengthobject derived from this instance's associated password.doubleCallsgetGuesses(Strength)and passes theStrengthobject derived from this instance's associated password.static doublegetGuesses(com.nulabinc.zxcvbn.Strength strength) Return the estimated number of guesses that would be needed to crack a password with thisStrength.com.nulabinc.zxcvbn.WipeableStringGet a reference to theWipeableStringcontaining the password associated with this instance.intgetScore()CallsgetScore(Strength)and passes theStrengthobject derived from this instance's associated password.static intgetScore(com.nulabinc.zxcvbn.Strength strength) Return an integer from 0 to 4 representing the strength score of a password with thisStrength.CallsgetStrengthSummary(Strength)and passes theStrengthobject derived from this instance's associated password.static StringgetStrengthSummary(com.nulabinc.zxcvbn.Strength strength) Analyze aStrengthobject and provide a summary with relevant metrics.static com.nulabinc.zxcvbn.Strengthmeasure(char[] password) Measures the strength of a password and returns aStrengthobject representing the results.static StringparseFeedback(com.nulabinc.zxcvbn.Feedback feedback) Parse the content of the givenFeedbackinstance into a nicely formattedStringshowing relevant warnings and suggestions.intsearch()Consult the Pwned Passwords API to find if this instance's associated password has been exposed in a reported data breach.voidsetPassword(char[] password) Set a new password for this instance to operate on.voidwipe()Wipe sensitive password-related information from memory by callingStrength.wipe()on theStrengthobject generated from the password associated to this instance.Methods inherited from class com.nulabinc.zxcvbn.Zxcvbn
createMatching, measure, measure
-
Constructor Details
-
PasswordCritic
public PasswordCritic(char[] password) Construct an instance ofPasswordCriticready to operate on the given password. This constructor automatically zeroes out the passedchar[]to increase security.- Parameters:
password- thechar[]representing the password to be tested.
-
-
Method Details
-
measure
public static com.nulabinc.zxcvbn.Strength measure(char[] password) Measures the strength of a password and returns aStrengthobject representing the results. Only use this method if you wish to manage passwords and work withStrengthobjects directly, otherwise just pass passwords usingPasswordCritic(char[])andsetPassword(char[]).- Parameters:
password- thechar[]representing the password to be tested.- Returns:
- a
Strengthobject representing the password's strength.
-
getPassword
public com.nulabinc.zxcvbn.WipeableString getPassword()Get a reference to theWipeableStringcontaining the password associated with this instance. Please note that thisWipeableStringwill be wiped if a new password is set usingsetPassword(char[])or if thewipe()method is called on this object.- Returns:
- a reference to the
WipeableStringcontaining the password.
-
setPassword
public void setPassword(char[] password) Set a new password for this instance to operate on. This method automatically zeroes out the passedchar[]and callswipe()to remove previous password-related information for security.- Parameters:
password- thechar[]representing the password to be tested.
-
getGuesses
public static double getGuesses(com.nulabinc.zxcvbn.Strength strength) Return the estimated number of guesses that would be needed to crack a password with thisStrength.- Parameters:
strength- theStrengthof the password in question.- Returns:
- a
doublerepresenting the guess estimate.
-
getGuesses
public double getGuesses()CallsgetGuesses(Strength)and passes theStrengthobject derived from this instance's associated password.- Returns:
- a
doublerepresenting the guess estimate.
-
getScore
public static int getScore(com.nulabinc.zxcvbn.Strength strength) Return an integer from 0 to 4 representing the strength score of a password with thisStrength. The scores are given as follows:- 0 (Weak):
getGuesses(Strength)< 10^3 + 5 - 1 (Fair):
getGuesses(Strength)< 10^6 + 5 - 2 (Good):
getGuesses(Strength)< 10^8 + 5 - 3 (Strong):
getGuesses(Strength)< 10^10 + 5 - 4 (Very strong):
getGuesses(Strength)>= 10^10 + 5
- Parameters:
strength- theStrengthof the password in question.- Returns:
- an
intrepresenting the strength score.
- 0 (Weak):
-
getScore
public int getScore()CallsgetScore(Strength)and passes theStrengthobject derived from this instance's associated password.- Returns:
- an
intrepresenting the strength score.
-
getCalcTime
public static double getCalcTime(com.nulabinc.zxcvbn.Strength strength) Return a double representing the time (in seconds) that it took to calculate a password'sStrength.- Parameters:
strength- theStrengthof the password in question.- Returns:
- a
doublerepresenting theStrength's calculation time.
-
getCalcTime
public double getCalcTime()CallsgetCalcTime(Strength)and passes theStrengthobject derived from this instance's associated password.- Returns:
- a
doublerepresenting theStrength's calculation time.
-
getCrackTimesEstimate
Return a nicely formattedStringwith estimates on how long it'd take to crack a password with thisStrength.- Parameters:
strength- theStrengthof the password in question.- Returns:
- a pretty
Stringwith crack time estimates.
-
getCrackTimesEstimate
CallsgetCrackTimesEstimate(Strength)and passes theStrengthobject derived from this instance's associated password.- Returns:
- a pretty
Stringwith crack time estimates.
-
parseFeedback
Parse the content of the givenFeedbackinstance into a nicely formattedStringshowing relevant warnings and suggestions.- Parameters:
feedback- theFeedbackassociated to the password in question.- Returns:
- a pretty
Stringwith feedback, i.e. warnings and suggestions, or an empty one if there's none.
-
getFeedback
CallsparseFeedback(Feedback)and passes theFeedbackobject generated from theStrengthobject derived from this instance's associated password.- Returns:
- a pretty
Stringwith feedback, i.e. warnings and suggestions, or an empty one if there's none.
-
getStrengthSummary
Analyze aStrengthobject and provide a summary with relevant metrics.- Parameters:
strength- theStrengthobject to analyze.- Returns:
- a pretty
Stringwith information on a password's associatedStrength.
-
getStrengthSummary
CallsgetStrengthSummary(Strength)and passes theStrengthobject derived from this instance's associated password.- Returns:
- a pretty
Stringwith information on the password's associated Strength.
-
search
public int search()Consult the Pwned Passwords API to find if this instance's associated password has been exposed in a reported data breach.- Returns:
- the number of occurrences of this password in data breach reports.
-
critique
Provide an assessment of this instance's associated password using all the available information. Presents the strength summary provided bygetStrengthSummary()and the number of occurrences of this password in data breach reports provided bysearch().- Returns:
- a pretty
Stringwith a fully-detailed assessment of this password.
-
wipe
public void wipe()Wipe sensitive password-related information from memory by callingStrength.wipe()on theStrengthobject generated from the password associated to this instance.
-