Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save scottcagno/de1810471fcb530fc396 to your computer and use it in GitHub Desktop.

Select an option

Save scottcagno/de1810471fcb530fc396 to your computer and use it in GitHub Desktop.
Spring Security - Password Encode Example
In SecurityConfig.java (config)
======================
...
auth.jdbcAuthentication()
.dataSource(...)
.passwordEncoder(passEncoder()) <--- ADD
.usersByUsernameQuery(...)
.authoritiesByUsernameQuery(...);
...
@Bean
private PasswordEncoder passEncoder() { <--- ADD
return new BCryptPasswordEncoder();
}
...
NOTE: The above is all you should really have to do. If you
want some manual control over things, or test anything out
you can always implement something like the following...
In User.java (domain)
============
...
// modify setPassword(...)
private void setPassword(String password) {
PasswordEncoder encoder = new BCryptPasswordEncoder();
this.password = encoder.encode(password);
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment