Posted By

soup on 04/28/11


Tagged

php hash


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

tux-world


php password hash function


 / Published in: PHP
 

  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  

You need to login to post a comment.