DBCrypt class
BCrypt implements OpenBSD-style Blowfish password hashing using the scheme described in "A Future-Adaptable Password Scheme" by Niels Provos and David Mazieres.
This password hashing system tries to thwart off-line password cracking using a computationally-intensive hashing algorithm, based on Bruce Schneier's Blowfish cipher. The work factor of the algorithm is parameterised, so it can be increased as computers get faster.
Usage is really simple. To hash a password for the first time, call the hashpw method with a random salt, like this:
String pw_hash = new DBCrypt().hashpw(plain_password, new DBCrypt().gensalt());
To check whether a plaintext password matches one that has been hashed previously, use the checkpw method:
if (new DBCrypt().checkpw(candidate_password, stored_hash)) System.out.println("It matches"); else System.out.println("It does not match");
The gensalt() method takes an optional parameter (log_rounds) that determines the computational complexity of the hashing:
String strong_salt = new DBCrypt().gensalt(10) String stronger_salt = new DBCrypt().gensalt(12)
The amount of work increases exponentially (2**log_rounds), so each increment is twice as much work. The default log_rounds is 10, and the valid range is 4 to 31.
@author Erlantz Oniga @version 0.1.0
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
checkpw(
String plaintext, String hashed) → bool - Check that a plaintext password matches a previously hashed one.
-
gensalt(
) → String -
Generate a salt for use with the
BCrypt.hashpw
method, selecting a reasonable default for the number of hashing rounds to apply. -
gensaltWithRounds(
int log_rounds) → String -
Generate a salt for use with the
BCrypt.hashpw
method. -
gensaltWithRoundsAndRandom(
int log_rounds, Random random) → String -
Generate a salt for use with the
BCrypt.hashpw
method. -
hashpw(
String password, String salt) → String - Hash a password using the OpenBSD bcrypt scheme.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited