Spring Boot,MySQL:如何使用哈希密码进行数据库身份验证?

时间:2015-12-31 12:10:14

标签: java hash spring-security spring-boot password-encryption

您好我有一个Spring Boot应用程序,它只有1个Admin,没有用户。 我已经创建了一个名为“administrator”的表,其中包含用户名和带有哈希密码的String。 (我把密码放在转换器中。)

现在我的问题是我应该更改}中的内容,以便代码使用我在登录表单中编写的字符串检查数据库中的哈希值,以便能够登录。

我的代码:

WebSecurityConfiguration.java

我发现了以下内容,但我仍然不知道该怎么做:

1 个答案:

答案 0 :(得分:0)

看起来像这样:

@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {

auth.jdbcAuthentication().dataSource(this.dataSource)
.usersByUsernameQuery("select email, password, active from user where email=?")
.authoritiesByUsernameQuery("select u.email, r.role from user u inner join user_role ur on(u.user_id=ur.user_id) inner join role r on(ur.role_id=r.role_id) where u.email=?").passwordEncoder(passwordencoder());
 }

@Bean(name="passwordEncoder")
    public PasswordEncoder passwordencoder(){
     return new BCryptPasswordEncoder();
    }