How do we Validate a User? #676
-
For issue #668 I want to validate a password before the user is deleted. Originally my code to do this looked like this |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
The bearer token validation should work. I think you're trying to check whether the encoded password stored for the user matches the cleartext (unencrypted) password passed in, which is different if (userService.getCurrentUser().getPassword().equals(passwordEncoder.encode(password))) { If we look at the method description for
In particular, note that the BCryptPasswordEncoder also uses a randomly generated salt (emphasis mine). As we don't want know what the salt is, we should be using a different method. Instead, we can use the public boolean matches(java.lang.CharSequence rawPassword, java.lang.String encodedPassword) Method description:
The subtle difference here is that it can tell us whether they match without us having to concern ourselves with the salt used to encrypt the password stored in the database. See the Spring documentation for more information on this method (it's below |
Beta Was this translation helpful? Give feedback.
The bearer token validation should work. I think you're trying to check whether the encoded password stored for the user matches the cleartext (unencrypted) password passed in, which is different
If we look at the method description for
encode()
in the Spring documentation, we can see the following:In particular, note that the BCryptPasswordEncoder also uses a randomly generated salt (emphasis mine). As we don't want know what the salt i…