So far my application is hashing user passwords using simple MD5 algorithm now we have introduced Spring Security in the application and would prefer using BCrypt instead. My problem how can I migrate old passwords to new Algorithm.
- Can I give multiple password encoders to Spring Security so that they can be used in turn ?
- After successful login how to change the password since password is transmitted using SHA1 algorithm ?
For problem 1, I believe using CustomAuthenticationProvider may work but I am totally confused about how to use that in our system. Below is my configureGlobal function from SecurityConfig class
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.jdbcAuthentication()
.dataSource(dataSource)
.passwordEncoder(passwordEncoder)
.usersByUsernameQuery("SELECT uname AS username, upwd AS password, true AS enabled FROM user_table WHERE uname!='' AND uname IS NOT NULL AND uname=?")
.authoritiesByUsernameQuery("SELECT uname AS username, 'Default' AS role FROM user_table WHERE uname!='' AND uname IS NOT NULL AND uname=?");
}
I have not used UserDetailsService in my application and only above queries are supplied. I have used CustomUsernamePasswordAutheticationFilter and CustomPasswordEncoder if that can be useful in this problem.
Thanks,