Advertisement
Guest User

Untitled

a guest
Jun 30th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. <?php
  2. include_once $_SERVER['DOCUMENT_ROOT'].'/api/includes.php';
  3. function Authenticate($username, $password) {
  4. $getInfo = $GLOBALS['db']->prepare("SELECT * FROM users WHERE username = :username");
  5. $getInfo->bindParam(":username", $username, PDO::PARAM_STR);
  6. $getInfo->execute();
  7. $dbcheck = $getInfo->fetch(PDO::FETCH_ASSOC);
  8. if(password_verify($password, $dbcheck['password'])) {
  9. $_SESSION['loggedin'] = true;
  10. } else {
  11. $invalidlogin = true;
  12. }
  13. }
  14. function Signup($username, $password, $passwordconfirm) {
  15. $exists = $GLOBALS['db']->prepare("SELECT * FROM users WHERE username = :username");
  16. $exists->bindParam(":username", $username, PDO::PARAM_STR);
  17. $exists->execute();
  18. if($exists->rowCount() < 1) {
  19. if($password == $passwordconfirm) {
  20. $hashedpw = password_hash($password, PASSWORD_DEFAULT);
  21. $accountCreation = $GLOBALS['db']->prepare("INSERT INTO users (username, password) VALUES (:username, :password)");
  22. $accountCreation->bindParam(":username", $username, PDO::PARAM_STR);
  23. $accountCreation->bindParam(":password", $hashedpw, PDO::PARAM_STR);
  24. $accountCreation->execute();
  25. echo '
  26. <div class="alert alert-success" role="alert">
  27. <button type="button" class="close" data-dismiss="alert">×</button>
  28. <strong>Well done!</strong> Your account was created.
  29. </div>';
  30. } else {
  31. $error = "Your password confirmation does not match the password you inputted.";
  32. echo '
  33. <div class="alert alert-danger" role="alert">
  34. <button type="button" class="close" data-dismiss="alert">×</button>
  35. <strong>Uh oh...</strong> Your password confirmation didn\'t match your password!
  36. </div>';
  37. }
  38. } else {
  39. $error = "There is already a user with that username";
  40. echo '
  41. <div class="alert alert-danger" role="alert">
  42. <button type="button" class="close" data-dismiss="alert">×</button>
  43. <strong>Uh oh...</strong> There is already a user named ' . $username . '!
  44. </div>';
  45. }
  46.  
  47. }
  48. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement