我的密码盐应该多大? [英] How large should my password salt be?

查看:125
本文介绍了我的密码盐应该多大?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

用户密码盐的最佳长度是多少?

我有一个数据库,如下所示:

I have a database like below:

create table user (id int primary key auto increment,
     username varchar(64),
     password varchar(128), # sha512 hash of password
     password_salt varchar(128) # sha512 hash of a random number used as salt
)

这是确保盐密码安全的好主意吗?盐要多久?我假设有一个128位(SHA-512)盐不能伤害,但以前我错了。

Is this a good idea for ensuring password security with a salt? How long should a salt be? I assume that it can't hurt to have a 128bit (SHA-512) salt, but I've been wrong before.

推荐答案

我有几个意见:


  • 盐对于每个用户来说应该是随机和唯一的,但是他们不必是哈希摘要。盐的想法只是使每个用户的哈希消息独特,以抵抗字典攻击和彩虹表攻击。盐不会增加哈希摘要算法的强度,而不考虑盐的长度。

  • Salts should be random and unique per user, but they don't have to be a hash digest. The idea of a salt is just to make the hash digest unique per user to resist dictionary attacks and rainbow table attacks. The salt doesn't add to the strength of the hash digest algorithm, regardless of the salt's length.

DES使用12位盐。更新的UNIX密码系统使用更多,最多128位。

DES uses 12 bits for the salt. Updated UNIX password systems use more, up to 128 bits.

如果您想要更强大的密码,请考虑使用 bcrypt PBKDF2

If you want stronger passwords, consider using bcrypt or PBKDF2.

FWIW,SHA-512哈希摘要(以十六进制数字编码)始终为128个字符,无论输入的长度如何。所以我会使用CHAR(128)而不是VARCHAR(128)。使用BINARY(2)或BINARY(3)作为盐。

FWIW, a SHA-512 hash digest (encoded as hex digits) is always exactly 128 characters, regardless of the length of the input. So I'd use CHAR(128) instead of VARCHAR(128). Use BINARY(2) or BINARY(3) for the salt.

这篇关于我的密码盐应该多大?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆