Advertisement
Guest User

Untitled

a guest
May 27th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. $(document).on("submit", ".loginForm", function(event) {
  2.  
  3. event.preventDefault();
  4.  
  5. var url=$(this).attr("action");
  6. $.ajax({
  7. url: url,
  8. type: 'POST',
  9. data: new FormData(this),
  10. processData: false,
  11. contentType: false,
  12. datatype: "json",
  13. success: function (data, status)
  14. {
  15. if(data.success == "success"){
  16. window.location.replace("dashboard.php");
  17. } else {
  18. $('#loginResponse').html(data.success).css("color", "red").fadeIn().delay(2000).slideToggle();
  19. }
  20. }
  21. });
  22.  
  23. header("Content-Type: application/json", true);
  24.  
  25. if(isset($_POST['submit_login'])) {
  26.  
  27. $username = $_POST['username'];
  28. $password = $_POST['password'];
  29.  
  30. $sql = 'SELECT user_id, first_name, password FROM arbor_admin_users WHERE username=?';
  31.  
  32. $stmt = $connection->prepare($sql);
  33. $stmt->bind_param('s', $username);
  34. $stmt->bind_result($uid, $fn, $pwhash);
  35. $stmt->execute();
  36. $stmt->store_result();
  37. if($stmt->num_rows > 0) {
  38. while($stmt->fetch()){
  39.  
  40.  
  41. // if ($password === $pw) {
  42. if (password_verify($password, $pwhash)) {
  43. session_start();
  44. $_SESSION['logged_in'] = $uid;
  45. $_SESSION['firstname'] = $fn;
  46. // header("Location: ../dashboard.php");
  47. echo json_encode(array('success'=>"success"));
  48. exit();
  49.  
  50. } else {
  51.  
  52. echo json_encode(array('success'=>"Wrong username or password!"));
  53.  
  54. }
  55. }
  56. } else {
  57. echo json_encode(array('success'=>"Wrong username or password!"));
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement