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:
  • WipeableString
  • Strength
  • HashFunction
  • Retrofit
  • Constructor Summary

    Constructors
    Constructor
    Description
    PasswordCritic(char[] password)
    Construct an instance of PasswordCritic ready to operate on the given password.
  • Method Summary

    Modifier and Type
    Method
    Description
    Provide an assessment of this instance's associated password using all the available information.
    double
    Calls getCalcTime(Strength) and passes the Strength object derived from this instance's associated password.
    static double
    getCalcTime(com.nulabinc.zxcvbn.Strength strength)
    Return a double representing the time (in seconds) that it took to calculate a password's Strength.
    Calls getCrackTimesEstimate(Strength) and passes the Strength object derived from this instance's associated password.
    static String
    getCrackTimesEstimate(com.nulabinc.zxcvbn.Strength strength)
    Return a nicely formatted String with estimates on how long it'd take to crack a password with this Strength.
    Calls parseFeedback(Feedback) and passes the Feedback object generated from the Strength object derived from this instance's associated password.
    double
    Calls getGuesses(Strength) and passes the Strength object derived from this instance's associated password.
    static double
    getGuesses(com.nulabinc.zxcvbn.Strength strength)
    Return the estimated number of guesses that would be needed to crack a password with this Strength.
    com.nulabinc.zxcvbn.WipeableString
    Get a reference to the WipeableString containing the password associated with this instance.
    int
    Calls getScore(Strength) and passes the Strength object derived from this instance's associated password.
    static int
    getScore(com.nulabinc.zxcvbn.Strength strength)
    Return an integer from 0 to 4 representing the strength score of a password with this Strength.
    Calls getStrengthSummary(Strength) and passes the Strength object derived from this instance's associated password.
    static String
    getStrengthSummary(com.nulabinc.zxcvbn.Strength strength)
    Analyze a Strength object and provide a summary with relevant metrics.
    static com.nulabinc.zxcvbn.Strength
    measure(char[] password)
    Measures the strength of a password and returns a Strength object representing the results.
    static String
    parseFeedback(com.nulabinc.zxcvbn.Feedback feedback)
    Parse the content of the given Feedback instance into a nicely formatted String showing relevant warnings and suggestions.
    int
    Consult the Pwned Passwords API to find if this instance's associated password has been exposed in a reported data breach.
    void
    setPassword(char[] password)
    Set a new password for this instance to operate on.
    void
    Wipe sensitive password-related information from memory by calling Strength.wipe() on the Strength object generated from the password associated to this instance.

    Methods inherited from class com.nulabinc.zxcvbn.Zxcvbn

    createMatching, measure, measure

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • PasswordCritic

      public PasswordCritic(char[] password)
      Construct an instance of PasswordCritic ready to operate on the given password. This constructor automatically zeroes out the passed char[] to increase security.
      Parameters:
      password - the char[] 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 a Strength object representing the results. Only use this method if you wish to manage passwords and work with Strength objects directly, otherwise just pass passwords using PasswordCritic(char[]) and setPassword(char[]).
      Parameters:
      password - the char[] representing the password to be tested.
      Returns:
      a Strength object representing the password's strength.
    • getPassword

      public com.nulabinc.zxcvbn.WipeableString getPassword()
      Get a reference to the WipeableString containing the password associated with this instance. Please note that this WipeableString will be wiped if a new password is set using setPassword(char[]) or if the wipe() method is called on this object.
      Returns:
      a reference to the WipeableString containing the password.
    • setPassword

      public void setPassword(char[] password)
      Set a new password for this instance to operate on. This method automatically zeroes out the passed char[] and calls wipe() to remove previous password-related information for security.
      Parameters:
      password - the char[] 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 this Strength.
      Parameters:
      strength - the Strength of the password in question.
      Returns:
      a double representing the guess estimate.
    • getGuesses

      public double getGuesses()
      Calls getGuesses(Strength) and passes the Strength object derived from this instance's associated password.
      Returns:
      a double representing 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 this Strength. The scores are given as follows:
      Parameters:
      strength - the Strength of the password in question.
      Returns:
      an int representing the strength score.
    • getScore

      public int getScore()
      Calls getScore(Strength) and passes the Strength object derived from this instance's associated password.
      Returns:
      an int representing 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's Strength.
      Parameters:
      strength - the Strength of the password in question.
      Returns:
      a double representing the Strength's calculation time.
    • getCalcTime

      public double getCalcTime()
      Calls getCalcTime(Strength) and passes the Strength object derived from this instance's associated password.
      Returns:
      a double representing the Strength's calculation time.
    • getCrackTimesEstimate

      public static String getCrackTimesEstimate(com.nulabinc.zxcvbn.Strength strength)
      Return a nicely formatted String with estimates on how long it'd take to crack a password with this Strength.
      Parameters:
      strength - the Strength of the password in question.
      Returns:
      a pretty String with crack time estimates.
    • getCrackTimesEstimate

      public String getCrackTimesEstimate()
      Calls getCrackTimesEstimate(Strength) and passes the Strength object derived from this instance's associated password.
      Returns:
      a pretty String with crack time estimates.
    • parseFeedback

      public static String parseFeedback(com.nulabinc.zxcvbn.Feedback feedback)
      Parse the content of the given Feedback instance into a nicely formatted String showing relevant warnings and suggestions.
      Parameters:
      feedback - the Feedback associated to the password in question.
      Returns:
      a pretty String with feedback, i.e. warnings and suggestions, or an empty one if there's none.
    • getFeedback

      public String getFeedback()
      Calls parseFeedback(Feedback) and passes the Feedback object generated from the Strength object derived from this instance's associated password.
      Returns:
      a pretty String with feedback, i.e. warnings and suggestions, or an empty one if there's none.
    • getStrengthSummary

      public static String getStrengthSummary(com.nulabinc.zxcvbn.Strength strength)
      Analyze a Strength object and provide a summary with relevant metrics.
      Parameters:
      strength - the Strength object to analyze.
      Returns:
      a pretty String with information on a password's associated Strength.
    • getStrengthSummary

      public String getStrengthSummary()
      Calls getStrengthSummary(Strength) and passes the Strength object derived from this instance's associated password.
      Returns:
      a pretty String with 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

      public String critique()
      Provide an assessment of this instance's associated password using all the available information. Presents the strength summary provided by getStrengthSummary() and the number of occurrences of this password in data breach reports provided by search().
      Returns:
      a pretty String with a fully-detailed assessment of this password.
    • wipe

      public void wipe()
      Wipe sensitive password-related information from memory by calling Strength.wipe() on the Strength object generated from the password associated to this instance.