A user password should never be stored in clear-text, instead a hash should be produced from it using a secure algorithm:
brute force attacks
. collision attacks
(see rule s4790). rainbow table attacks
(see rule s2053). This rule raises an issue when a password is stored in clear-text or with a hash algorithm vulnerable to bruce force attacks
. These
algorithms, like md5
or SHA-family
functions are fast to compute the hash and therefore brute force attacks are possible
(it's easier to exhaust the entire space of all possible passwords) especially with hardware like GPU, FPGA or ASIC. Modern password hashing
algorithms such as bcrypt
, PBKDF2
or argon2
are recommended.
@Autowired public void configureGlobal(AuthenticationManagerBuilder auth, DataSource dataSource) throws Exception { auth.jdbcAuthentication() .dataSource(dataSource) .usersByUsernameQuery("SELECT * FROM users WHERE username = ?") .passwordEncoder(new StandardPasswordEncoder()); // Noncompliant // OR auth.jdbcAuthentication() .dataSource(dataSource) .usersByUsernameQuery("SELECT * FROM users WHERE username = ?"); // Noncompliant; default uses plain-text // OR auth.userDetailsService(...); // Noncompliant; default uses plain-text // OR auth.userDetailsService(...).passwordEncoder(new StandardPasswordEncoder()); // Noncompliant }
@Autowired public void configureGlobal(AuthenticationManagerBuilder auth, DataSource dataSource) throws Exception { auth.jdbcAuthentication() .dataSource(dataSource) .usersByUsernameQuery("Select * from users where username=?") .passwordEncoder(new BCryptPasswordEncoder()); // or auth.userDetailsService(null).passwordEncoder(new BCryptPasswordEncoder()); }