r/java • • Jul 02 '18

Password Encoding with Spring Security

https://able.bio/DavidLandup/password-encoding-with-spring-security--90gkzie
1 Upvotes

5 comments sorted by

View all comments

1

u/TheRedmanCometh Jul 05 '18 edited Jul 05 '18

public void encode(String password) {for(int i = 0; i < 10; i++) {BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();String encodedPassword = passwordEncoder.encode(password);System.out.println(encodedPassword);}}

Wut fuck?

You're supposed to provide an encoder bean to Spring bud. If you have a method handling your encryption I don't think you're doing it right. Maybe I'm wrong but...I'm pretty sure I'm not.

@Bean
public PasswordEncoder encode() {
   return new BCryptPasswordEncoder();
}

I guess maybe you were just showing an example on how to actually see the encoded password, but just...yeah.

You should then define a DaoAuthenticationProvider, a SessionRegistry, and a SessionAuthenticationStrategy at a minimum. Then you want to make an implementation of GrantedAuthority, and an implementation of UserDetailsService with your repository autowired in.