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 Details

  • Method Details

    • generatePassword

      public final String generatePassword()
      Generate a random password.
      Returns:
      A password consisting of 16 random ASCII printable characters.
    • encodePassword

      public final String encodePassword​(String password)
      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 be null.
      Returns:
      The encoded password. Will be null if the input is null.
    • matchPassword

      public final boolean matchPassword​(String password, String encodedPassword)
      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. If null, the encoded form must also be null for a match to be true.
      encodedPassword - The encoded form from the database.
      Returns:
      True if the password matches, false otherwise.