Home >Database >Mysql Tutorial >What Database Column Type and Length Should I Use for Bcrypt Hashed Passwords?

What Database Column Type and Length Should I Use for Bcrypt Hashed Passwords?

Susan Sarandon
Susan SarandonOriginal
2024-12-14 10:12:12651browse

What Database Column Type and Length Should I Use for Bcrypt Hashed Passwords?

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:

  • Binary safe: Stores the hashed value as a binary string without any character conversion.
  • Fixed length: Maintains a consistent length for all stored passwords.

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:

  • 22 characters of salt
  • 31 characters of encrypted output

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn