Class PasswordServices
java.lang.Object
uk.ac.manchester.spinnaker.alloc.security.PasswordServices
@Component public class PasswordServices extends Object
Misc services related to password handling.
- Author:
- Donal Fellows
-
Constructor Summary
Constructors Constructor Description PasswordServices()
-
Method Summary
Modifier and Type Method Description String
encodePassword(String password)
Encode a password with bcrypt.String
generatePassword()
Generate a random password.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.
-