question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Encoded password does not look like BCrypt

See original GitHub issue

Is it just me or has anyone else got an error like o.s.s.c.bcrypt.BCryptPasswordEncoder : Encoded password does not look like BCrypt?

public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
   @Autowired
    CustomUserDetailsService customUserDetailsService;
   .....
   @Bean
    public static PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder(16);
    }
    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.authenticationProvider(authenticationProvider());
    }
    @Bean
    public DaoAuthenticationProvider authenticationProvider() {
        DaoAuthenticationProvider authenticationProvider = new DaoAuthenticationProvider();
        authenticationProvider.setUserDetailsService(customUserDetailsService);
        authenticationProvider.setPasswordEncoder(passwordEncoder());
        return authenticationProvider;
    }
}

Service:

@Autowired
    PasswordEncoder passwordEncoder;
user.setPassword(passwordEncoder.encode(user.getPassword()));

The encrypted password looks like $2a$16$AYSTH/JEPXPwqYBRswLq0emwmItvsQgf.dnaffXGJpvYML97bBoGe in the db, but when I try to log in, I get the error. P.s.: I am using this with OAuth2 Spring boot 5.0.4.RELEASE

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

15reactions
AlicanBalikcommented, Apr 10, 2018

Sure. First, open your security configuration which extends WebSecurityConfigurerAdapter and paste below function:

@Bean
public static PasswordEncoder passwordEncoder() {
      return PasswordEncoderFactories.createDelegatingPasswordEncoder();
}

Then in the same configuration file, modify your authenticationProvider() function like this:

 @Bean
 public DaoAuthenticationProvider authenticationProvider() {
      DaoAuthenticationProvider authenticationProvider = new DaoAuthenticationProvider();
      authenticationProvider.setUserDetailsService(customUserDetailsService);
      authenticationProvider.setPasswordEncoder(passwordEncoder());
      return authenticationProvider;
 }

Note: If you create multiple PasswordEncoder beans, the compiler will always select the first one. If you also need to implement NoOpPasswordEncoder, do it in the file that you really need to use it and create it without @Bean.

@SuppressWarnings("deprecation")
 public static NoOpPasswordEncoder passwordEncoder() {
     return (NoOpPasswordEncoder) NoOpPasswordEncoder.getInstance();
 }

In your service, or wherever you want to use you need to autowire the `PasswordEncoder`:
@Autowired
private PasswordEncoder passwordEncoder;

And you can encrypt your String like this: `passwordEncoder.encode("password");`
If you want to match a raw password with an encrypted one, you can do it with `passwordEncoder.matches("rawPassword", user.getPassword());` where `user.getPassword()` returns an encrypted password (from db).
2reactions
AlicanBalikcommented, Apr 1, 2018

Yes, I did. If you also have the same problem, you can follow here

Read more comments on GitHub >

github_iconTop Results From Across the Web

Encoded password does not look like BCrypt - Stack Overflow
The best way to identify this problem "Encoded password does not look like BCrypt" is setup a break porint in class ...
Read more >
Encoded password does not look like Bcrypt - Spring
To fix the login issue and get rid of the warning “Encoded password does not look like BCrypt”, either remove the {bcrypt} prefix...
Read more >
Spring Security : Encoded password does not look like BCrypt
A common mistake, the length of the “password” column (users table) is less than 60, for example, password VARCHAR(45) , and some databases...
Read more >
Encrypted Password does not look like BCrypt | Spring Boot 2
Encrypted Password does not look like BCrypt | Spring Boot 2 | Spring Security 5 | Spring Cloud ...
Read more >
[Solved]-Encoded password does not look like BCrypt
[Solved]-Encoded password does not look like BCrypt - spring security version is 5.3.2-Springboot ... You can specify the bcrypt version to use with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found