Database Column Type and Length for Storing Bcrypt Hashed Passwords
When storing Bcrypt hashed passwords in a database, it's essential to choose an appropriate column type and ensure the correct length for data integrity.
Column Type
According to the Modular Crypt Format for Bcrypt, the hashed value consists of 60 bytes. Therefore, for MySQL, the recommended column type is CHAR(60) BINARY or BINARY(60). This ensures that the column is:
Column Length
Bcrypt passwords are always 60 characters long, whether using the $2a$ or $2y$ format. This is because Bcrypt generates a fixed-length hash consisting of:
Database Implementation
If you are using jBCrypt for password hashing, the Bcrypt hashes will have a length of 60 characters.
The above is the detailed content of What Database Column Type and Length Should I Use for Bcrypt Hashed Passwords?. For more information, please follow other related articles on the PHP Chinese website!