密码哈希和验证

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了密码哈希和验证相关的知识,希望对你有一定的参考价值。

Calling generateHash() with a single argument (the plain text password) will cause a random string to be generated and used for the salt. The resulting string consists of the salt followed by the SHA-1 hash - this is to be stored away in your database. When you're checking a user's login, the situation is slightly different in that you already know the salt you'd like to use. The string stored in your database can be passed to generateHash() as the second argument when generating the hash of a user-supplied password for comparison.
  1. function generate_hash ($plain_text, $salt = null) {
  2.  
  3. if ($salt === null) {
  4. $salt = substr(md5(uniqid(rand(), true)), 0, 12);
  5. } else {
  6. $salt = substr($salt, 0, 12);
  7. }
  8.  
  9. return $salt . sha1($salt . $plain_text);
  10.  
  11. }

以上是关于密码哈希和验证的主要内容,如果未能解决你的问题,请参考以下文章

密码验证在德鲁的手册中不起作用(密码哈希)[重复]

C#:使用来自 /etc/shadow 的 linux 用户的 salt 验证密码哈希 (SHA512)

针对 Scrypt 组合哈希验证 python 密码:(设置+盐+哈希)

Java Active Directory LDAP - 使用密码哈希对用户进行身份验证

PHP 密码哈希和验证

密码哈希和验证