Guest User

Untitled

a guest
Jan 29th, 2019
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. public function set__password($passwd) {
  2. self::$password = password_hash($passwd, PASSWORD_BCRYPT, array('cost' => 12));
  3. }
  4.  
  5. $2y$12$lTMEP0wevDEMX0bzStzoyOEzOTIAi3Hyhd3nYjGwzbI
  6.  
  7. $username = $_POST['username'];
  8. $password = $_POST['password'];
  9.  
  10. $DB = Database::getInstance();
  11.  
  12. // Get the stored password hash
  13. $res = $DB->run__query('SELECT password FROM users WHERE username = "' . $username . '"');
  14. $hash = $res[0]['password'];
  15.  
  16.  
  17. // Do the passwords match?
  18. if(password_verify($password, $hash)) {
  19. echo 'success';
  20. } else {
  21. echo 'failed';
  22. }
  23.  
  24. if(isset($_POST['submit'])){
  25. include 'database.php';
  26. $uid = mysqli_real_escape_string($conn,$_POST['uid']);
  27. $pass = mysqli_real_escape_string($conn,$_POST['pass']);
  28.  
  29. $query = "SELECT * FROM user WHERE username ='$uid'";
  30. $tbl = mysqli_query($conn, $query);
  31. if (mysqli_num_rows($tbl)>0){
  32.  
  33. $row = mysqli_fetch_array($tbl, MYSQLI_ASSOC);
  34. $hash = $row['password'];
  35. if (password_verify($pass, $hash)){
  36. echo "success";
  37. }
  38. else {
  39. echo "log in error";
  40. }
  41.  
  42. }
  43. }
Add Comment
Please, Sign In to add comment