Advertisement
Guest User

Untitled

a guest
Mar 1st, 2019
546
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. <?php
  2. $servername = "";
  3. $username = "";
  4. $password = "";
  5. $database = "";
  6.  
  7. // Create connection
  8. $conn = new mysqli($servername, $username, $password, $database);
  9.  
  10. // Check connection
  11. if ($conn->connect_error) {
  12. die("Connection failed: " . $conn->connect_error);
  13. }
  14.  
  15. function getUserGroup($id, $conn){
  16. $stmt = $conn->prepare("select user_group_id from xf_user_group_relation where user_id = ? and is_primary = 1");
  17. $stmt->bind_param('i', $id);
  18. $stmt->execute();
  19. $stmt->bind_result($groups);
  20. $stmt->store_result();
  21. $stmt->fetch();
  22. $stmt->close();
  23. return $groups;
  24. }
  25.  
  26. function getUserPasswordHash($id, $conn)
  27. {
  28. $stmt = $conn->prepare("select data from xf_user_authenticate where user_id = ?");
  29. $stmt->bind_param('i', $id);
  30. $stmt->execute();
  31. $stmt->bind_result($messhash);
  32. $stmt->store_result();
  33. $stmt->fetch();
  34. $password = substr($messhash, 22, -3);
  35. $stmt->close();
  36. return $password;
  37. }
  38.  
  39. function getUserID($username, $conn){
  40. $stmt = $conn->prepare("select user_id from xf_user where username = ?");
  41. $stmt->bind_param('s', $username);
  42. $stmt->execute();
  43. $stmt->bind_result($userid);
  44. $stmt->store_result();
  45. $stmt->fetch();
  46. $stmt->close();
  47. return $userid;
  48. }
  49.  
  50. function checkUserPasswordHash($hash, $password){
  51. if(strlen($hash) < 5){
  52. die("This user has not setup a password");
  53. }
  54. return password_verify($password, $hash);
  55. }
  56.  
  57. $username = $_REQUEST['username'];
  58. $password = $_REQUEST['password'];
  59. if(!$username || !$password){
  60. die("All required parameters were not supplied");
  61. }
  62. $userid = getUserID($username, $conn);
  63. $passwordHash = getUserPasswordHash($userid, $conn);
  64. $correctPass = checkUserPasswordHash($passwordHash,$password);
  65. if(!$correctPass){
  66. die("Credentials enterd do not match our records.");
  67. }
  68. echo getUserGroup($userid, $conn);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement