I am currently coding a loadUserByUsername method in a UserDetailsServiceImpl java class similarily found in many springboot tutorials. The problem is in the last line
return new org.springframework.security.core.userdetails.User(user.getEmail(), user.getPassword(),
grantedAuthorities);
According to the spring security documentation, user.getPassword() should return a string, but I am using bcrypt and MySQL, so when I store the password, I store it in Mysql as binary(60) and when I read it into the user class from the database it is read into a
@Entity
@Data
@AllArgsConstructor
@NoArgsConstructor
public class users {
@Id
private String email;
private long phone_number;
private String first_name;
private String last_name;
private byte[] password;
private int gender;
}
field in my user class. If i convert it into a string Ive read that it messes up the password, but if I dont then the function doesnt work as I'm passing in a byte[] instead of a string. How can I keep the security of bcrypt while also maintaining this functionality?
Because in mysql docs it maps BINARY(60) to byte[] here https://dev.mysql.com/doc/ndbapi/en/mccj-using-clusterj-mappings.html
and everyone is saying to store bcrypt as binary(60) here What column type/length should I use for storing a Bcrypt hashed password in a Database?