php password hash function


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function crypt_pass($pass, $salt=NULL)
  2. {
  3. $salt_len=7;
  4. $algo='sha256';
  5.  
  6. if (!$salt||strlen($salt)<$salt_len)
  7. {
  8. $salt=uniqid(rand(), TRUE); // get unique string (length==23)
  9. }
  10. $salt=substr($salt, 0, $salt_len);
  11.  
  12. if (function_exists('hash') && in_array($algo, hash_algos()))
  13. {
  14. $hashed=hash($algo, $salt.$pass);
  15. }
  16. else
  17. {
  18. $hashed=sha1($salt.$pass);
  19. }
  20. return $salt.$hashed;
  21. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.