密码存储

- 用户输入
password
- 系统生成随机的字符串,我们称为
salt,符合 OWASP 标准
- 将
password和salt拼接起来,通过哈希函数计算出拼接后的密码字符串的哈希值
- 将
salt和hash存储至 DB 中
密码验证

- 用户输入密码,系统从 DB 中取出
salt
- 将用户输入的密码和系统中的
salt进行拼接,得到password+salt
- 计算
password+salt的哈希,我们暂且将其称为hash1
- 从 DB 中取出原本的哈希值,我们称其为
hash2
- 比较
hash1和hash2,得到验证结果
.png?table=block&id=12069987-7a3a-44ea-a377-8a6a69e1c67c&cache=v2)