Advertisement
Guest User

Untitled

a guest
Jan 26th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. <?php
  2.  
  3. //echo "login.php";
  4.  
  5. function logIn($username, $password, $ip) {
  6. require_once("connect.php");
  7. $username = mysqli_real_escape_string($link, $username);
  8. $password = mysqli_real_escape_string($link, $password);
  9. $loginString = "SELECT * FROM tbl_user WHERE user_name='{$username}' AND user_pass='{$password}'";
  10. $user_set = mysqli_query($link, $loginString);
  11. $attemptString = "SELECT user_attempt FROM tbl_user WHERE user_name='{$username}'";
  12. $users_attempts = mysqli_query($link, $attemptString);
  13. //echo $user_attempts;
  14. //echo $attemptString;
  15. //echo mysqli_num_rows($user_set); //was there a match
  16. date_default_timezone_set('US/Eastern');
  17. if(mysqli_num_rows($user_set)){
  18. $found_user = mysqli_fetch_array($user_set, MYSQLI_ASSOC);
  19. //echo $found_user ['user_fname'];
  20. $id = $found_user['user_id'];
  21. $_SESSION['users_creds'] = $id;
  22. $_SESSION['users_mylgn'] = $found_user['user_lstlgn'];
  23. $_SESSION['users_name'] = $found_user['user_name'];
  24. $_SESSION['users_fname'] = $found_user['user_fname'];
  25. //$userloginAttempts = "UPDATE tbl_user SET user_attempt='{$currentAttempt}' WHERE user_id={$id}";
  26. if(mysqli_query($link, $loginString)) {
  27. $updateString = "UPDATE tbl_user SET user_ip='{$ip}' WHERE user_id={$id}";
  28. $updateQuery = mysqli_query($link, $updateString);
  29. $currDate = date('Y-m-d H:i:s');
  30. $userloginTime = "UPDATE tbl_user SET user_lstlgn='{$currDate}' WHERE user_id={$id}";
  31.  
  32. $updateQueryTime = mysqli_query($link, $userloginTime);
  33. // $updateQueryLogins = mysqli_query($link, "UPDATE tbl_user SET user_attempt='0' WHERE user_id{$id}"); //reset count on successful login
  34.  
  35. }
  36.  
  37. redirect_to("admin_index.php");
  38.  
  39. }else{
  40. $attemptString = "SELECT user_attempt FROM tbl_user WHERE user_name='{$username}'";
  41. //$found_user = mysqli_fetch_array($attemptString, MYSQLI_ASSOC); //Errors
  42. $found_user = mysqli_fetch_array($users_attempts, MYSQLI_ASSOC);
  43. $attempts = $found_user['user_attempt'];
  44.  
  45. //Some stuff has been deleted and lost since then.
  46. //I won't lie, I'm giving up after ~4 hours of trying to get the attempts. I know a session would be a bad idea.
  47. if ($attempts > 2){
  48. echo "locked";
  49. $updateAttempt = "UPDATE tbl_user SET user_attempt = user_attempt +'1' WHERE user_name = '{$username}'";
  50. }
  51.  
  52.  
  53.  
  54. //for ($userAttempt = 0; $userAttempt <= 3;$userAttempts++){
  55. //$currentAttempt = $userAttempt;
  56. //$userloginAttempts = "UPDATE tbl_user SET user_attempt='{$currentAttempt}' WHERE user_id={$id}";
  57. //$updateQueryAttempts = mysqli_query($link, $userloginAttempts);
  58.  
  59. //$found_user = mysqli_fetch_array($user_set, MYSQLI_ASSOC);
  60. //echo $found_user ['user_fname'];
  61.  
  62. $message = "Username or password was incorrect. Please try again.";
  63. //echo $currentAttempt;
  64.  
  65. //if($currentAttempt > 3){
  66. //echo "oml";
  67. //}
  68.  
  69. return $message;
  70.  
  71. }
  72.  
  73.  
  74. mysqli_close($link);
  75. }
  76.  
  77. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement