public class BcryptPasswordHashFunction extends Object implements PasswordHashFunction
bcrypt password hash function which produces a string in modular crypt format.
Note: not using PHC string format as there is no definition for ID and parameters.Constructor and Description |
---|
BcryptPasswordHashFunction() |
Modifier and Type | Method and Description |
---|---|
boolean |
canHandle(String passwordHash)
Test whether the provided hash was generated by
PasswordHashFunction.generate(String) of this hash
function. |
boolean |
check(String passwordHash,
String password)
Test a clear text password against a password hash generated by this hash function.
|
String |
generate(String password)
Generate the hash of a clear text password.
|
int |
getCostFactorFromHash(String passwordHash) |
String |
getIdentifier() |
boolean |
needsUpdate(String passwordHash)
Test whether a password hash needs to be updated.
|
public boolean canHandle(String passwordHash)
PasswordHashFunction
PasswordHashFunction.generate(String)
of this hash
function.canHandle
in interface PasswordHashFunction
passwordHash
- a password hashpublic boolean check(String passwordHash, String password)
PasswordHashFunction
PasswordHashFunction.canHandle(String)
for the hash returns true.check
in interface PasswordHashFunction
passwordHash
- a hash generated by this functionpassword
- the clear text password to validatepublic String generate(String password)
PasswordHashFunction
PasswordHashFunction.canHandle(String)
) and to check the hash against a clear-text
password in PasswordHashFunction.check(String, String)
. The latter requires to include the salt
and any parameters like cost factors or iterations in the created string. A recommended way
to encode this information is the
PHC string
format.generate
in interface PasswordHashFunction
password
- the clear text password to hashpublic int getCostFactorFromHash(String passwordHash)
public String getIdentifier()
getIdentifier
in interface PasswordHashFunction
public boolean needsUpdate(String passwordHash)
PasswordHashFunction
PasswordHashFunction.generate(String)
. This method will only be called if
PasswordHashFunction.canHandle(String)
for the hash returns true.needsUpdate
in interface PasswordHashFunction
passwordHash
- a hash generated by this functionCopyright © 2019 Communote team. All rights reserved.