Advertisement
Guest User

Untitled

a guest
Jun 12th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. <?
  2.  
  3. // This script will take the username and password in via url using get protocol.
  4. // We then fetch them below, after fetching, We check the database for these details.
  5. // If existing we echo true, otherwise we echo false.
  6.  
  7. // Password is hashed and compared to hashed entry in database using if(verify) method.
  8.  
  9. if ($_GET["authcode"] == "s3cret") //Validating the session using auth code.
  10. {
  11.  
  12. //Getting the details from the URL
  13. $username = $_GET["username"];
  14. $password = $_GET["password"];
  15. $DBpassword = "s3cret";
  16. $found = false;
  17.  
  18. //Searching for the username in the DB
  19. $conn = new PDO("mysql:host=localhost; dbname=s3cret", s3cret, $DBpassword);
  20. $stmt = $conn->prepare("SELECT * FROM accounts WHERE `email` = '" . $username . "'");
  21. $stmt->execute();
  22.  
  23. foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row)
  24. {
  25. $found = true;
  26. $hashOnRecord = $row["password"];
  27. //Verify password
  28. if (password_verify($password, $hashOnRecord))
  29. {
  30. //The hash is verified.
  31. echo json_encode(found_valid);
  32. exit;
  33. }
  34. else
  35. {
  36. //The hash could not be verified.
  37. //Echo out an error.
  38. echo json_encode(found_invalid);
  39. exit;
  40. }
  41. }
  42.  
  43. if ($found == false)
  44. {
  45. //Nothing even found under that username
  46. echo json_encode(found_invalid);
  47. exit;
  48. }
  49. }
  50. else
  51. {
  52. //This will run if the user has the incorrect auth code.
  53. include 'access_denied.html';
  54. exit;
  55. }
  56. exit;
  57. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement