frostyfire

php -login

Aug 21st, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. <?php
  2.  
  3. $con = mysqli_connect('localhost', 'admin', 'admin', 'carnival_db');
  4.  
  5. //check that connection happened
  6. if (mysqli_connect_errno())
  7. {
  8. echo "1: Connection failed";
  9. exit();
  10. }
  11.  
  12. $username = $_POST["name"];
  13. $password = $_POST["password"];
  14.  
  15. //check if name exists
  16. $namecheckquery = "SELECT username, salt, hash, score, house FROM players WHERE username='".$username."';";
  17.  
  18. $namecheck = mysqli_query($con, $namecheckquery) or die("2: Name check query failed");
  19.  
  20. if(mysqli_num_rows($namecheck) != 1)
  21. {
  22. echo "5: Either no user with name or more than 1"; //error code #5
  23. }
  24.  
  25. //get login info from query
  26. $existinginfo = mysqli_fetch_assoc($namecheck);
  27. $salt= $existinginfo["salt"];
  28. $hash= $existinginfo["hash"];
  29.  
  30. $loginhash = crypt($password, $salt);
  31. if ($hash != $loginhash)
  32. {
  33. echo "6:invalid password";// Invalid credentials
  34. exit();
  35.  
  36. }
  37.  
  38. echo "0";
  39. echo "\t";
  40. echo $existinginfo["score"];
  41. echo "\t";
  42. echo $existinginfo["house"];
  43.  
  44. ?>
Add Comment
Please, Sign In to add comment