gpt4 book ai didi

mysql - Spring 启动安全 : Encoded password does not look like BCrypt

转载 作者:行者123 更新时间:2023-11-29 07:28:02 24 4
gpt4 key购买 nike

我最近学习了 spring boot security 中的身份验证和授权教程,我想当涉及到 sql 时我迷路了。虽然它没有显示任何错误,但即使我输入了正确的用户名和密码,它仍然显示错误的凭据。这是我的代码:

UserDetailsS​​erviceImpl.java

    @Override
public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException {
WebUser appUser = this.appUserDAO.findUserAccount(userName);

if (appUser == null) {
System.out.println("User not found! " + userName);
throw new UsernameNotFoundException("User " + userName + " was not found in the database");
}

System.out.println("Found User: " + appUser);

// [ROLE_USER, ROLE_ADMIN,..]
List<String> roleNames = this.appRoleDAO.getRoleNames(appUser.getId());

List<GrantedAuthority> grantList = new ArrayList<GrantedAuthority>();
if (roleNames != null) {
for (String role : roleNames) {
// ROLE_USER, ROLE_ADMIN,..
GrantedAuthority authority = new SimpleGrantedAuthority(role);
grantList.add(authority);
}
}

UserDetails userDetails = (UserDetails) new User(appUser.getUsername(), //
appUser.getPass(), grantList);

return userDetails;
}

WebUserMapper.java

public static final String BASE_SQL //
= "Select u.Id, u.Username, u.Pass From User u ";

@Override
public WebUser mapRow(ResultSet rs, int rowNum) throws SQLException {

Long userId = rs.getLong("Id");
String userName = rs.getString("Username");
String encrytedPassword = rs.getString("Pass");

return new WebUser(userId, userName, encrytedPassword);
}

WebSecurityConfig.java

    @Bean
public BCryptPasswordEncoder passwordEncoder() {
BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
return bCryptPasswordEncoder;
}

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

// Setting Service to find User in the database.
// And Setting PassswordEncoder
auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());

}

这是我的数据库:

enter image description here

它返回这个错误:

Found User: test/$2y$12$MemyV61IuKV7SAntLOEVqeLPPvl2snXjQwlk3RSFDmn5eWrRcHwxm
2018-10-21 20:32:57.110 WARN 1300 --- [nio-8080-exec-3] o.s.s.c.bcrypt.BCryptPasswordEncoder : Encoded password does not look like BCrypt

密码是123,不知道为什么我输入了“123”还是不行,希望大家能帮帮我。非常感谢

最佳答案

尝试使用 bcrypt 编码器在服务器端对您的 client_secret 进行编码。

关于mysql - Spring 启动安全 : Encoded password does not look like BCrypt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52915452/

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