Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring Boot,MySQL:如何使用哈希密码进行数据库身份验证?_Java_Hash_Spring Security_Spring Boot_Password Encryption - Fatal编程技术网

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

Java Spring Boot,MySQL:如何使用哈希密码进行数据库身份验证?,java,hash,spring-security,spring-boot,password-encryption,Java,Hash,Spring Security,Spring Boot,Password Encryption,你好,我有一个Spring启动应用程序,它只有一个管理员,没有用户。 我已经创建了一个名为“administrator”的表,其中包含用户名和带有哈希密码的字符串。(我将密码放入转换器中以执行此操作。) 现在我的问题是我应该在WebSecurityConfiguration.java中更改什么,以便代码使用我在登录表单中编写的字符串检查数据库中的哈希值,以便能够登录 我的代码: @Autowired public void configureGlobal(AuthenticationManage

你好,我有一个Spring启动应用程序,它只有一个管理员,没有用户。 我已经创建了一个名为“administrator”的表,其中包含用户名和带有哈希密码的字符串。(我将密码放入转换器中以执行此操作。)

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

我的代码:

@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication()
            .withUser("admin").password("admin").roles("ADMIN");

 }
我发现了以下问题,但我仍然不知道该怎么办:


它看起来是这样的:

@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();
    }

它看起来是这样的:

@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();
    }

你看过医生了吗?我查看了它,但它并没有真正显示如何进行身份验证。我读到我需要对密码进行编码。但我不知道我必须做什么更改,它对我在WebSecurity中定义的密码进行编码,保存在数据库中,并能够在我尝试授权时从数据库中对其进行编码。例如,请参阅并使用
PasswordEncoder
作为
BCryptPasswordEncoder
,因此,您可以将Spring Security配置为密码的单向编码器。密码永远不应该被解码,这是安全最佳实践之一。你读过文档了吗?我查看了它,但它并没有真正显示如何进行身份验证。我读到我需要对密码进行编码。但我不知道我必须做什么更改,它对我在WebSecurity中定义的密码进行编码,保存在数据库中,并能够在我尝试授权时从数据库中对其进行编码。例如,请参阅并使用
PasswordEncoder
作为
BCryptPasswordEncoder
,因此,您可以将Spring Security配置为密码的单向编码器。密码永远不应该被解码,这是安全最佳实践之一。