Advertisement
Guest User

Simple Password hash in PHP

a guest
Mar 10th, 2014
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.45 KB | None | 0 0
  1. <?php
  2.  
  3. function password_hash ($password) {
  4.     return crypt($password, '$5$rounds=5000$'. md5(mcrypt_create_iv(16, MCRYPT_DEV_URANDOM)) .'$');
  5. }
  6.  
  7. function password_verify ($password, $crypted) {
  8.     return crypt($password, $crypted) == $crypted;
  9. }
  10.  
  11. // create a hash
  12. $hash = password_hash('sample password');
  13.  
  14. // verify a hash
  15. if (password_verify('sample password', $hash)) {
  16.     echo 'Password is valid!';
  17. } else {
  18.     echo 'Invalid password.';
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement