Class Argon2PasswordEncoder

java.lang.Object
org.ametys.plugins.core.impl.hash.Argon2PasswordEncoder

public class Argon2PasswordEncoder extends Object
Password encoder using Argon2 hashing algorithm.
  • Field Details

    • ROLE

      public static final String ROLE
      Avalon Role
  • Constructor Details

    • Argon2PasswordEncoder

      public Argon2PasswordEncoder(byte[] pepper)
      Constructor for Argon2PasswordEncoder
      Parameters:
      pepper - the pepper used by the Argon2PasswordEncoder
  • Method Details

    • getOrCreatePepper

      public static byte[] getOrCreatePepper(String id) throws IOException
      Get a pepper for a given id and generate it if it does not already exists
      Parameters:
      id - the id of the pepper
      Returns:
      the value of the paper
      Throws:
      IOException - if I/O error occurred.
    • encode

      public String encode(CharSequence rawPassword)
      Encode the raw password with argon2id hash algorithm.
      Parameters:
      rawPassword - the raw password
      Returns:
      the hash
    • matches

      public boolean matches(CharSequence rawPassword, String encodedPassword)
      Verify the encoded password obtained from storage matches the submitted raw password after it too is encoded. Returns true if the passwords match, false if they do not. The stored password itself is never decoded.
      Parameters:
      rawPassword - the raw password to encode and match
      encodedPassword - the encoded password from storage to compare with
      Returns:
      true if the raw password, after encoding, matches the encoded password from storage