Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.28 KB | None | 0 0
  1. if (isset($_POST['btn-login']))
  2. {
  3. $LoginID = mysqli_real_escape_string($conn, $_POST['username']);
  4. $Password = $_POST['password'];
  5.  
  6. $sql = "SELECT *, SUBSTRING_INDEX(Name, ' ', 1) AS ShortName FROM users_db WHERE UserID = '".$LoginID."'";
  7. $res = mysqli_query($conn, $sql);
  8. $row = mysqli_fetch_array($res);
  9.  
  10. $count = mysqli_num_rows($res); // if username/pass correct it returns must be 1 row
  11. if($count < 1 )
  12. {
  13. echo "errmsg1";
  14. }
  15. else if($count == 1 && $row['Password']==password_verify($Password, $row['Password']) && $row['AccountStatus']=="Pending")
  16. {
  17. echo "errmsg2";
  18. else if($count == 1 && $row['Password']==password_verify($Password, $row['Password']) && $row['AccountStatus']=="Active")
  19. //session variables set here.
  20. }
  21. else
  22. {
  23. echo "errmsg3";
  24. }
  25. }
  26.  
  27. <script>
  28. /*
  29. Login Validation Script
  30. */
  31.  
  32. $('document').ready(function()
  33. {
  34. /* validation */
  35. $("#login-form").validate({
  36. rules:
  37. {
  38. password: {
  39. required: true,
  40. },
  41. username: {
  42. required: true,
  43. },
  44. },
  45. messages:
  46. {
  47. password:{
  48. required: "Password field cannot be empty."
  49. },
  50. username:{
  51. required: "A Login ID is required."
  52. },
  53. },
  54. submitHandler: submitForm
  55. });
  56. /* validation */
  57.  
  58. /* login submit */
  59. function submitForm()
  60. {
  61. var data = $("#login-form").serialize();
  62.  
  63. $.ajax({
  64.  
  65. type : 'POST',
  66. url : 'processlogin.php',
  67. data : data,
  68. beforeSend: function()
  69. {
  70. $("#loginerror").fadeOut();
  71. $("#btn-submit").html('<img src="include/btn-ajax-loader.gif" /> &nbsp; Verifying');
  72. },
  73. success : function(response)
  74. {
  75. if(response=="success"){
  76. $("#btn-submit").html('<img src="include/btn-ajax-loader.gif" /> &nbsp; Signing In...');
  77. setTimeout(' window.location.href = "index.php"; ',4000);
  78. }
  79. else if(response=="errmsg1"){
  80. $("#loginerror").fadeIn(1000, function(){
  81. $("#loginerror").html('<span>The Login ID provided does not exist.</span>');
  82. $("#btn-submit").html('Login');
  83. });
  84. }
  85. else if(response=="errmsg2"){
  86. $("#loginerror").fadeIn(1000, function(){
  87. $("#loginerror").html('<span>This account is Pending Activation.</span>');
  88. $("#btn-submit").html('Login');
  89. });
  90. }
  91. else if (response=="errmsg3"){
  92. $("#loginerror").fadeIn(1000, function(){
  93. $("#loginerror").html('<span">Unknown Error</span>');
  94. $("#btn-submit").html('Login');
  95. });
  96. }
  97. }
  98. });
  99. return false;
  100. }
  101. /* login submit */
  102. });
  103. </script>
  104.  
  105. catch(PDOException $e){
  106. echo $e->getMessage();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement