Java Spring安全编码的密码看起来不像BCrypt
我无法使用正确的详细信息登录,因为程序不断声明编码的密码看起来不像bcrypt。有人知道如何解决这个问题吗?我正在使用JDBC身份验证 我也有正确的数据库表,有足够的空间存放编码的密码。我不确定哪里出了问题 JSP表单: 登录控制器Java Spring安全编码的密码看起来不像BCrypt,java,spring,spring-mvc,spring-security,Java,Spring,Spring Mvc,Spring Security,我无法使用正确的详细信息登录,因为程序不断声明编码的密码看起来不像bcrypt。有人知道如何解决这个问题吗?我正在使用JDBC身份验证 我也有正确的数据库表,有足够的空间存放编码的密码。我不确定哪里出了问题 JSP表单: 登录控制器 @Controller public class LoginController { @Autowired private UserServiceImpl userService; @GetMapping("/login") public S
@Controller
public class LoginController {
@Autowired
private UserServiceImpl userService;
@GetMapping("/login")
public String showLoginForm(Model model) {
User user = new User();
model.addAttribute("user", user);
return "login";
}
@PostMapping("/processLogin")
public String processLogin(@ModelAttribute("user") User user, Model model) {
if (userService.findUser(user.getUsername(), user.getPassword()) != null) {
return "/management/dashboard";
} else {
return "/access-denied";
}
}
}
我的数据库:查看您的数据库条目,您似乎在使用
org.springframework.security.crypto.password.DelegatingPasswordEncoder
一次,然后切换回org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
。
只有DelegatingPasswordEncoder能够处理使用不同方案编码的密码
如果您想继续使用当前配置的BCryptPasswordEncoder,您需要
{bcrypt}
john
和susan
的两个密码test123
进行编码查看数据库条目,您似乎使用了
org.springframework.security.crypto.password.DelegatingPasswordEncoder
一次,然后切换回org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
。
只有DelegatingPasswordEncoder能够处理使用不同方案编码的密码
如果您想继续使用当前配置的BCryptPasswordEncoder,您需要
{bcrypt}
john
和susan
的两个密码test123
进行编码我使用
BcryptPasswordEncoder
解决了我的问题,如下所示
@Override
public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException {
User user = userRepository.findByuserName(userName);
if (user == null) {
throw new UsernameNotFoundException("userName" + userName + "Not found in the database");
}
return new org.springframework.security.core.userdetails.User(user.getName(), new BCryptPasswordEncoder().encode(user.getPassword()), getGrantedAuth(user));
}
我使用
BcryptPasswordEncoder
解决了我的问题,如下所示
@Override
public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException {
User user = userRepository.findByuserName(userName);
if (user == null) {
throw new UsernameNotFoundException("userName" + userName + "Not found in the database");
}
return new org.springframework.security.core.userdetails.User(user.getName(), new BCryptPasswordEncoder().encode(user.getPassword()), getGrantedAuth(user));
}
如果问题得到解决,请考虑接受帮助的答案。如果问题得到解决,请考虑接受帮助的答案。
@Override
public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException {
User user = userRepository.findByuserName(userName);
if (user == null) {
throw new UsernameNotFoundException("userName" + userName + "Not found in the database");
}
return new org.springframework.security.core.userdetails.User(user.getName(), new BCryptPasswordEncoder().encode(user.getPassword()), getGrantedAuth(user));
}