Java 使用spring安全密码编码器处理盐
我惊讶地看到,Spring Security PasswordEncoder(我使用的实现是BCryptPasswordEncoder,如果这有区别的话)在编码密码时生成了salt 我不明白的是,在验证登录请求时,我应该如何获得这个salt?我打算使用我自己的salt,但是(大概)由于salt的自动生成,我对相同的密码+salt组合得到了不同的散列值Java 使用spring安全密码编码器处理盐,java,spring,spring-security,Java,Spring,Spring Security,我惊讶地看到,Spring Security PasswordEncoder(我使用的实现是BCryptPasswordEncoder,如果这有区别的话)在编码密码时生成了salt 我不明白的是,在验证登录请求时,我应该如何获得这个salt?我打算使用我自己的salt,但是(大概)由于salt的自动生成,我对相同的密码+salt组合得到了不同的散列值 我有点困惑,不知道如何正确使用编码器。您应该使用内置验证逻辑,而不是编写自己的密码验证函数。因此,您不需要获得Spring Security生成的
我有点困惑,不知道如何正确使用编码器。您应该使用内置验证逻辑,而不是编写自己的密码验证函数。因此,您不需要获得Spring Security生成的盐。请参阅
PasswordEncoder
中的文档:
/**
* 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.
*
* @param rawPassword the raw password to encode and match
* @param encodedPassword the encoded password from storage to compare with
* @return true if the raw password, after encoding, matches the encoded password from
* storage
*/
boolean matches(CharSequence rawPassword, String encodedPassword);