Class PasswordServices
java.lang.Object
uk.ac.manchester.spinnaker.alloc.security.PasswordServices
Misc services related to password handling.
- Author:
- Donal Fellows
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal String
encodePassword
(String password) Encode a password with bcrypt.final String
Generate a random password.final boolean
matchPassword
(String password, String encodedPassword) Check using bcrypt if a password matches its encoded form retrieved from the database.
-
Constructor Details
-
PasswordServices
public PasswordServices()
-
-
Method Details
-
generatePassword
Generate a random password.- Returns:
- A password consisting of 16 random ASCII printable characters.
-
encodePassword
Encode a password with bcrypt. This is a slow operation! Do not hold a database transaction open when calling this.- Parameters:
password
- The password to encode. May benull
.- Returns:
- The encoded password. Will be
null
if the input isnull
.
-
matchPassword
Check using bcrypt if a password matches its encoded form retrieved from the database. This is a slow operation! Do not hold a database transaction open when calling this.- Parameters:
password
- The password to check. Ifnull
, the encoded form must also benull
for a match to be true.encodedPassword
- The encoded form from the database.- Returns:
- True if the password matches, false otherwise.
-