Guest User

Untitled

a guest
Apr 13th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. $salt = 'csdnfgksdgojnmfnb';
  2.  
  3. $password = md5($salt.$_POST['password']);
  4. $result = mysql_query("SELECT id FROM users
  5. WHERE username = '".mysql_real_escape_string($_POST['username'])."'
  6. AND password = '$password'");
  7.  
  8. if (mysql_num_rows($result) < 1) {
  9. /* Access denied */
  10. echo "The username or password you entered is incorrect.";
  11.  
  12. } else {
  13. $_SESSION['id'] = mysql_result($result, 0, 'id');
  14. #header("Location: ./");
  15. echo "Hello $_SESSION[id]!";
  16. }
  17.  
  18. require('PasswordHash.php');
  19.  
  20. $pwdHasher = new PasswordHash(8, FALSE);
  21.  
  22. // $hash is what you would store in your database
  23. $hash = $pwdHasher->HashPassword( $password );
  24.  
  25. // $hash would be the $hashed stored in your database for this user
  26. $checked = $pwdHasher->CheckPassword($password, $hash);
  27. if ($checked) {
  28. echo 'password correct';
  29. } else {
  30. echo 'wrong credentials';
  31. }
  32.  
  33. <?php
  34. // generates a 8 character hexadecimal CRC32 string
  35. function crc($o){
  36. return str_pad(dechex(crc32($o)), 8, 0, STR_PAD_LEFT);
  37. }
  38.  
  39. $salt = crc(mt_rand() . time); // a unique fixed length salt
  40. $hash = sha1($password . $salt) . $salt; // generates a 40 character hash (32+8)
  41.  
  42. ?>
  43.  
  44. <?php
  45.  
  46. $hash = $TheHashFromDatabase;
  47.  
  48. $salt = substr($hash, -8);
  49. $generated_hash = sha1($_POST['user_pwd'] . $salt) . $salt;
  50.  
  51. if($generated_hash == $hash){
  52. // logged in - password is correct
  53. }
  54.  
  55. ?>
Add Comment
Please, Sign In to add comment