Advertisement
Guest User

Untitled

a guest
Jan 27th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.23 KB | None | 0 0
  1. <?php
  2. include_once('createtables.php');
  3. include('function.php');
  4.  
  5. ?>
  6.  
  7. <!DOCTYPE html>
  8. <html lang="en">
  9. <head>
  10. <title></title>
  11. <meta charset="utf-8">
  12. <meta name="viewport" content="width=device-width, initial-scale=1">
  13. <link rel="stylesheet" href="../includes/css/bootstrap.min.css">
  14. <link rel="stylesheet" href="../includes/css/main.css">
  15. <script src="../includes/js/jQuery.js"></script>
  16. <script src="../includes/js/login.js"></script>
  17. <script src="../includes/js/bootstrap.min.js"></script>
  18. </head>
  19. <body>
  20. <div class="container-fluid">
  21. <form id="lgform" action="checklogin.php" method="post">
  22. <h4 class="text-primary" id="llc"><img src="../includes/img/chatballoon.png"> Network Chat </h4>
  23.  
  24. <div class="input-group" id="firstone">
  25. <span class="input-group-addon">
  26. <span class="glyphicon glyphicon-user"></span>
  27. </span>
  28. <input type="text" class="form-control" placeholder="Enter Account name" id="username" name="username" autofocus>
  29. </div>
  30. <div class="input-group" id="secondtwo">
  31. <span class="input-group-addon" id="password-addon">
  32. <span class="glyphicon glyphicon-lock"></span>
  33. </span>
  34. <input type="password" class="form-control" placeholder="Enter your password" aria-decribedby="password-addon" id="password" name="password" autofocus>
  35. </div>
  36. <a href="createaccount.php" id="signup">Create Account</a>
  37. <input type="submit" class="pull-right btn btn-primary btn-sm" name="submit" id="submit" value="Enter now">
  38. </form>
  39. </div>
  40. </body>
  41. </html>
  42.  
  43. <?php
  44. ob_start();
  45. session_start();
  46.  
  47. include("function.php");
  48.  
  49. $conn = new Functions();
  50. $conn = $conn->db;
  51.  
  52. //define username and password
  53.  
  54. $username = $_POST['username'];
  55. $password = $_POST['password'];
  56.  
  57. $username = stripslashes($username);
  58. $password = stripcslashes($password);
  59. $salt = "dctech2015ABcRXd";
  60. $password = md5($password) . $salt;
  61. $password = sha1($password);
  62.  
  63.  
  64. //SELECT QUERY TO FIND IF INPUT INFORMATION WAS ON DATABASE
  65. $stmt = $conn->query("SELECT * FROM users WHERE username ='$username' AND password='$password'");
  66.  
  67. //LOOP ENTIRE DATABASE ROW
  68. $count = $stmt->rowCount();
  69.  
  70. //IF INFORMATION FOUND SELECT STATUS IF ALREADY ONLINE OR NOT
  71. if($count == 1){
  72. $status;
  73. $stmt = $conn->prepare("SELECT status FROM users WHERE username='$username'");
  74. $stmt->execute();
  75. while($checkstatus = $stmt->fetch(PDO::FETCH_OBJ)){
  76. $status = $checkstatus->status;
  77. }
  78. if($status == 'Online'){
  79. echo "online";
  80.  
  81. }else{
  82.  
  83. echo "success";
  84. $_SESSION['username'] = $username;
  85. $_SESSION['password'] = $password;
  86.  
  87. $stmt = $conn->prepare("UPDATE users SET status='Online' WHERE username='$username'");
  88. $stmt->execute();
  89. }
  90.  
  91. }
  92.  
  93. ob_end_flush();
  94. ?>
  95.  
  96. $(document).ready(function(){
  97. $("#submit").click(function(e){
  98. e.preventDefault();
  99.  
  100. var username = document.getElementById("username").value;
  101. var password = document.getElementById("password").value;
  102.  
  103. if(username==""){
  104. alert("Please enter your account name");
  105. }else if(password == ""){
  106. alert("Please enter your password");
  107. }else{
  108. $.ajax({
  109. type: "POST",
  110. url: "checklogin.php",
  111. data: "username="+username+"&password="+password,
  112. success: function(data){
  113. if(data == "success"){
  114. window.location.href="chat.php";
  115. }
  116. else if(data == "online"){
  117. alert("account is already online");
  118. }else{
  119. alert("Invalid Account name/Account password");
  120. }
  121. },error:function(data){
  122. alert("an error occured through data");
  123. }
  124. });
  125. }
  126.  
  127. document.getElementById("username").value = "";
  128. document.getElementById("password").value = "";
  129. });
  130. return false;
  131. });
  132.  
  133. if($count == 1){
  134. ...
  135. } else {
  136. header("HTTP/1.1 401 Unauthorized");
  137. // or for php 5.4:
  138. http_response_code(401);
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement