【问题标题】:Spring Security bcrypt constructorSpring Security bcrypt 构造函数
【发布时间】:2014-06-24 15:58:15
【问题描述】:

我有一个关于在 spring security 中实现 bcrypt 的问题。类“org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder” 在 bcrypt 的第一个构造函数中,我看到“this(-1);”这到底是什么意思。据我了解,这应该指“强度”字段,默认值应该是 org.springframework.security.crypto.bcrypt.BCrypt “private static final int GENSALT_DEFAULT_LOG2_ROUNDS = 10;”中设置的 10,但那是什么 - 1 指,第一个构造函数?

public class BCryptPasswordEncoder implements PasswordEncoder {
    private Pattern BCRYPT_PATTERN = Pattern.compile("\\A\\$2a?\\$\\d\\d\\$[./0-9A-Za-z]{53}");
    private final Log logger = LogFactory.getLog(getClass());

    private final int strength;

    private final SecureRandom random;

    public BCryptPasswordEncoder() {
        this(-1);
    }

【问题讨论】:

    标签: constructor spring-security bcrypt


    【解决方案1】:

    既然你已经做到了,为什么不看看where it's used in remainder of the file

    除非值大于零,否则只是调用默认的JBCrypt genSalt函数:

    BCrypt.gensalt();
    

    这又是uses the default strength setting

    【讨论】:

    • 这有点尴尬。感谢您的回复,下次我会三思而后行。
    猜你喜欢
    • 2019-03-25
    • 2019-12-22
    • 2021-04-04
    • 2019-03-18
    • 2012-05-01
    • 2016-07-10
    • 2012-10-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多