Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: What maximum length to set a password field in a database?

Tags:

database

php

hash

when I hash my password using hash('sha512', $salt . $password);, should the maximum length in the password column in the database be 512 or does it matter if it gets chopped down? Or can it possibly be longer than 512? Thanks.

like image 609
Andy Lobel Avatar asked Dec 01 '22 06:12

Andy Lobel


2 Answers

SHA512 actually returns a string of 128 length. So the short answer is, your field only needs to be 128 characters.

like image 92
afuzzyllama Avatar answered Dec 04 '22 07:12

afuzzyllama


SHA512 outputs 512 bits, or 64 bytes. You can store those 64 bytes in a binary column, which are represented by 128 hexadecimal numbers...

Hense you need 128 size..

For remainig See here

like image 29
Rajat Singhal Avatar answered Dec 04 '22 07:12

Rajat Singhal