PHP:在数据库中设置密码字段的最大长度是多少?

时间:2022-04-13 21:40:55

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.

当我使用hash('sha512',$ salt。$ password);哈希我的密码时,如果数据库中密码列的最大长度为512,或者它是否会被切断?或者它可能超过512?谢谢。

4 个解决方案

#1


12  

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

SHA512实际上返回128个字符串的字符串。简而言之,您的字段只需要128个字符。

#2


3  

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

SHA512输出512位或64字节。您可以将这64个字节存储在二进制列中,这些字节由128个十六进制数字表示...

Hense you need 128 size..

Hense你需要128尺寸..

For remainig Watch here

对于stillig,请在这里观看

#3


1  

Just a demonstration to see the length of the hashed password

只是一个演示来查看哈希密码的长度

$password = 'password';
$salt = 'salt';

$hash = hash('sha512', $salt.$password);

echo strlen($hash); // OUTPUTS 128

#4


1  

This depends on the length of the string that the hash algorithm you're using produces. The comment posted here shows that the length of the string produced by the sha512 algorithm you've chosen is 128 characters in length. Therefore, your field should be 128 characters. It can be more, but it's unnecessary. Making it less would trim the password down and thereby make your hashed passwords "invalid".

这取决于您正在使用的哈希算法生成的字符串的长度。此处发布的注释显示,您选择的sha512算法生成的字符串长度为128个字符。因此,您的字段应为128个字符。它可以更多,但它是不必要的。减少密码将减少密码,从而使您的散列密码“无效”。

#1


12  

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

SHA512实际上返回128个字符串的字符串。简而言之,您的字段只需要128个字符。

#2


3  

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

SHA512输出512位或64字节。您可以将这64个字节存储在二进制列中,这些字节由128个十六进制数字表示...

Hense you need 128 size..

Hense你需要128尺寸..

For remainig Watch here

对于stillig,请在这里观看

#3


1  

Just a demonstration to see the length of the hashed password

只是一个演示来查看哈希密码的长度

$password = 'password';
$salt = 'salt';

$hash = hash('sha512', $salt.$password);

echo strlen($hash); // OUTPUTS 128

#4


1  

This depends on the length of the string that the hash algorithm you're using produces. The comment posted here shows that the length of the string produced by the sha512 algorithm you've chosen is 128 characters in length. Therefore, your field should be 128 characters. It can be more, but it's unnecessary. Making it less would trim the password down and thereby make your hashed passwords "invalid".

这取决于您正在使用的哈希算法生成的字符串的长度。此处发布的注释显示,您选择的sha512算法生成的字符串长度为128个字符。因此,您的字段应为128个字符。它可以更多,但它是不必要的。减少密码将减少密码,从而使您的散列密码“无效”。