gpt4 book ai didi

java - spring security or BCrypt algorithm 哪一个对项目这样的账户有好处?

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:37:10 28 4
gpt4 key购买 nike

我正在使用 spring security 来散列我的密码。它安全吗,因为我是第一次使用 spring security。

我的代码在这里

<security:http auto-config="true">
<security:intercept-url pattern="/welcome*" access="ROLE_USER" />
<security:form-login login-page="/login" default-target-url="/welcome"
authentication-failure-url="/loginfailed" />
<security:logout logout-success-url="/logout" />
</security:http>
authentication-failure-url="/loginfailed" />
<security:logout logout-success-url="/logout" />
</security:http>
<authentication-manager>
<authentication-provider>
<password-encoder hash="sha" />
<user-service>
<user name="k" password="7c4a8d09ca3762af61e59520943dc26494f8941b"
authorities="ROLE_USER" />
</user-service>
</authentication-provider>
</authentication-manager>

。我还没有使用 bcrypt 算法。您对这两种算法有何反馈?有什么建议吗?

最佳答案

只是添加到 Serge 的回答中,

您可以配置您的 AuthenticationProvider通过像这样声明密码编码器 bean 来自动使用 BCrypt:

<beans:bean id="passwordEncoder" class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder" />

然后将对此 bean 的引用传递给您的 AuthenticationProvider像这样:

<authentication-manager alias="authenticationManager">
<authentication-provider>
<!-- Your actual auth provider here -->
<password-encoder ref="passwordEncoder" />
</authentication-provider>
</authentication-manager>

正如 Serge 所说,BCrypt 更安全地防止暴力破解密码,并且作为一个额外的好处,编码器 bean 可以是 @Autowired到您的类中,这样您就可以在创建新用户时以编程方式对密码进行编码。

@Autowired
private BCryptPasswordEncoder encoder;

public void createUser(User user){
user.setPassword(encoder.encode("passwordStringHere");
.
.
.
}

关于java - spring security or BCrypt algorithm 哪一个对项目这样的账户有好处?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24006599/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com