Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a mysql "sha-256" column?

For a password column, is there a mysql feature to store password hashed with "sha-256"? Or should I hash it from java code (like How to hash some string with sha256 in Java? ) before I store it in database and then hash the password input every time and compare with the database column value to authenticate?

TIA.

like image 379
Daemonthread Avatar asked Aug 12 '12 11:08

Daemonthread


1 Answers

You can convert the value to hex and use a char(n) column with the appropriate length - 64 in this case. The conversion can be done in MySQL by using the sha2 function with hash_length set to 256.

But for security reasons you should not store passwords hashed using SHA-256.

Instead use bcrypt or PBKDF2.

Related

  • How can I hash a password in Java?
like image 129
Mark Byers Avatar answered Sep 23 '22 11:09

Mark Byers