Class JBCryptPasswordEncoder

  • All Implemented Interfaces:
    PasswordEncoder

    public class JBCryptPasswordEncoder
    extends Object
    implements PasswordEncoder
    A password encoder for bcrypt and using a salt. Add the jBcrypt dependency to use this class.
    Since:
    1.9.2
    Author:
    Victor Noël
    • Constructor Detail

      • JBCryptPasswordEncoder

        public JBCryptPasswordEncoder​(String salt)
        Parameters:
        salt - the salt to hash with (perhaps generated using BCrypt.gensalt())
        See Also:
        BCrypt
      • JBCryptPasswordEncoder

        public JBCryptPasswordEncoder()
        Use the default salt generated by BCrypt.gensalt().
    • Method Detail

      • encode

        public String encode​(String password)
        Description copied from interface: PasswordEncoder
        Encode a password.
        Specified by:
        encode in interface PasswordEncoder
        Parameters:
        password - the not encoded password
        Returns:
        the encoded password
      • matches

        public boolean matches​(String plainPassword,
                               String encodedPassword)
        Description copied from interface: PasswordEncoder
        Validate if a plainPassword matches
        Specified by:
        matches in interface PasswordEncoder
        Parameters:
        plainPassword - the not encoded password to check
        encodedPassword - the encoded password
        Returns:
        true if they match
      • getSalt

        public String getSalt()
      • setSalt

        public void setSalt​(String salt)
        Parameters:
        salt - the salt to hash with (perhaps generated using BCrypt.gensalt())
        See Also:
        BCrypt