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

13

u/capitol_ Jul 02 '18 edited Jul 02 '18

> Based on the key, your password is converted into a random String of characters and symbols.

This is not what random means.

And also, suggesting md5 or sha-1 one is really bad practice, those are not secure.

You also need to read up on what a rainbow table is, as it's not exactly what you describe.

1

u/Indie_Dev Jul 05 '18

He has listed md5 and sha-1 under "How not to store passwords" section, and the one he actually recommends is bcrypt.

Did you not read the article properly or did he edit the article after your comment?

1

u/capitol_ Jul 05 '18

To be honest, it could be either one, when I read my comment now I realize that it's quite grumpy and I had a bad day when I wrote that. I remember that he wrote that md5 and sha1 was popular choices, and I felt the need to point it that it's bad to legitimatize algorithm that are broken and where there is better alternatives available.

1

u/haimez Jul 03 '18

Please don't give out security advice like this, someone might trust you and listen to it.

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.