Guest User

Untitled

a guest
Jan 13th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. PHP/AJAX Login taking very long
  2. <form name="login-form" onsubmit="return false">
  3. <input type="text" id="the_username" value="Username" onfocus="emptyUsername(this);" onblur="clickrecall(this,'Username')" class="focusfield input push" />
  4. <input type="password" id="the_password" value="Password" class="input" onfocus="emptyPassword(this);" onblur="clickrecall(this,'Password')" />
  5. <span id="dialog-login-fail" title="Login failed"></span>
  6. <input type="submit" onclick="javascript:void(0);" id="loginBtnBre" class="sign-in signin-submit-btn" value="Login Now" />
  7. </form>
  8.  
  9. <?php
  10. require 'config.inc.php';
  11.  
  12. foreach($_POST as $k=>$v)
  13. {
  14. $_POST[$k] = trim($v);
  15. }
  16.  
  17. if(!isset($_POST['theusername']) or !isset($_POST['thepassword']))
  18. {
  19. print "Please use all fields";
  20. }elseif(empty($_POST['theusername'])){
  21. print "Please enter a username";
  22. }elseif(empty($_POST['thepassword'])){
  23. print "Please enter a password";
  24. }elseif($_POST['theusername'] == "username" && $_POST['thepassword'] == "password")
  25. {
  26. print "Password & User cannot be the ones already listed";
  27. }elseif(!preg_match("/^[a-z0-9]+$/i", $_POST['theusername']))
  28. {
  29. print "Please use only characters and numbers for username, no spaces, dashes or others!";
  30. }else{
  31.  
  32. $password = md5($_POST['thepassword']);
  33. $user = $_POST['theusername'];
  34.  
  35. $loginVar = $usersClass->login($user, $password);
  36.  
  37. if(is_array($loginVar))
  38. {
  39. $_SESSION['loggedIn'] = $loginVar;
  40. @session_regenerate_id(true);
  41.  
  42. print "success";
  43.  
  44. }else{
  45. print "Whoops, something went wrong! Try again.";
  46. }
  47. }
  48.  
  49. ?>
  50.  
  51. public function login($username, $password)
  52. {
  53.  
  54. $rs = mysql_query("SELECT `id`,`active` from `$this->usersTable` WHERE
  55. `username` = '".mysql_real_escape_string($username)."' AND
  56. `password` = '".mysql_real_escape_string($password)."'");
  57.  
  58. if($rs) {
  59. $row = @mysql_fetch_object($rs);
  60.  
  61. return $this->userInfo($row->id);
  62.  
  63. }else{
  64. return false;
  65. }
  66.  
  67. alter table `TableName` add index `username` (`username`(500));
  68. alter table `TableName` add index `password` (`password`(500));
Add Comment
Please, Sign In to add comment