Advertisement
Husam1093

Untitled

May 13th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.74 KB | None | 0 0
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <style>
  5. .error {color: #FF0000;}
  6. </style>
  7. <title>Login Form</title>
  8. </head>
  9. <body>
  10. <?php
  11. /*$str = "Hello";
  12. echo password_hash($str,1);*/
  13. // define variables and set to empty values
  14. $nameErr = "";
  15. $passwordErr = "";
  16. $user = "";
  17. $password = "";
  18.  
  19.  
  20. if ($_SERVER["REQUEST_METHOD"] == "POST")
  21. {
  22. if (empty($_POST["user"]))
  23. {
  24. $nameErr = "Name is required";
  25. } else
  26. {
  27. $user = test_input($_POST["user"]);
  28. // check if name only contains letters and whitespace
  29. if (!preg_match("/^[a-zA-Z0-9 ]*$/",$user))
  30. {
  31. $nameErr = "Only letters,number and white space allowed";
  32. }
  33. }
  34. if (empty($_POST["pass"]))
  35. {
  36. $passwordErr = "Password is required";
  37. } else {
  38. $password = test_input($_POST["pass"]);
  39. }
  40.  
  41. }
  42. function test_input($data)
  43. {
  44. $data = trim($data);
  45. $data = stripslashes($data);
  46. $data = htmlspecialchars($data);
  47. return $data;
  48. }
  49. ?>
  50.  
  51. <h2>Login Form</h2>
  52.  
  53. <?php
  54. $start = intval(isset($_POST['start'])?$_POST['start']:0);
  55. if(isset($_POST['previous'])){
  56. $start = $start -1;
  57. //if($start < 1) $start = 1;
  58. $start= max($start, 1);
  59. }
  60. else if(isset($_POST['next'])){
  61. $start = $start + 1;
  62. }
  63. else {
  64. $start = 1;
  65. }
  66. ?>
  67.  
  68. <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
  69. <script>
  70. function deleteBook(b) {
  71. $(document).ready(function() {
  72. var book = $(b).parent('td').prev('td').html();
  73. if(confirm("Are you sure you want to delete book - "+book+"?") == false){
  74. return;
  75. }
  76. var ids = $(b).attr('id').substr(6).split('-');
  77. var book_id_to_delete = ids[0];
  78. var user_id = ids[1];
  79. //alert("book_id is " + book_id_to_delete + ", user_id is " + user_id);
  80. $.ajax({
  81. type: "POST",
  82. url: "" + "deletebook.php",
  83. data: {
  84. 'book_id': book_id_to_delete,
  85. 'user_id': user_id,
  86. submit: 'submit',
  87. },
  88. success: function(res) {
  89. if (res == "deleted") {
  90. $(b).closest('tr').remove();
  91. } else {
  92. alert(res);
  93. }
  94. }
  95. });
  96. });
  97. }
  98. </script>
  99. <script>
  100. function sortTable(n) {
  101. var table, rows, switching, i, x, y, shouldSwitch, dir, switchcount = 0;
  102. table = document.getElementById("myTable");
  103. switching = true;
  104. dir = "asc";
  105. while (switching) {
  106. switching = false;
  107. rows = table.getElementsByTagName("TR");
  108. for (i = 1; i < (rows.length - 1); i++) {
  109. shouldSwitch = false;
  110. x = rows[i].getElementsByTagName("TD")[n];
  111. y = rows[i + 1].getElementsByTagName("TD")[n];
  112. if (dir == "asc") {
  113. if (x.innerHTML.toLowerCase() > y.innerHTML.toLowerCase()) {
  114. shouldSwitch= true;
  115. break;
  116. }
  117. } else if (dir == "desc") {
  118. if (x.innerHTML.toLowerCase() < y.innerHTML.toLowerCase()) {
  119. shouldSwitch = true;
  120. break;
  121. }
  122. }
  123. }
  124. if (shouldSwitch) {
  125. rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
  126. switching = true;
  127. switchcount ++;
  128. } else {
  129. if (switchcount == 0 && dir == "asc") {
  130. dir = "desc";
  131. switching = true;
  132. }
  133. }
  134. }
  135. }
  136. </script>
  137.  
  138. <form method="post" action="">
  139. Name: <input type="text" name="user" value="<?php echo $user;?>">
  140. <span class="error">* <?php echo $nameErr;?></span>
  141. <br><br>
  142. password: <input type="password" name="pass" value="<?php echo $password;?>" >
  143. <span class="error">* <?php echo $passwordErr;?></span>
  144. <br><br>
  145. <input type="submit" name="submit" value="Login">
  146. <br><br>
  147. <input type="hidden" value="<?php echo $start;?>" name="start"/>
  148. <button type="button" name="button" onclick="window.location.href='/ooRigester.php'">SignUp</button>
  149. <br><br>
  150. <input type='submit' name='previous' value='previous' method="post" <?php echo ($start <= 1 ? "disabled" : ""); ?>>
  151. <input type='submit' name='next' value='next' method="post"><br>
  152. </form>
  153. <br>
  154.  
  155. <?php
  156. include_once('User.php');
  157. if(isset($_POST['submit']) OR isset($_POST['next']) OR isset($_POST['previous'])){
  158. $username = $_POST["user"];
  159. $password = $_POST["pass"];
  160.  
  161. $object = new User();
  162. $object->username= $username;
  163. $object->Password=$password;
  164.  
  165. if( $object->isAuthenticated() ){
  166.  
  167. echo "User Verified . <br><br>";
  168.  
  169.  
  170. $start = 0;
  171.  
  172. if(isset($_POST['next']))
  173. {
  174. $start = $_POST['start'];
  175. }
  176. else if(isset($_POST['previous']))
  177. {
  178. $start = $_POST['start']-2;
  179. }
  180. $object->getBooks($start);
  181.  
  182. }
  183.  
  184. //For test git
  185. else{
  186. echo "Wrong User Name Or Password . Please try again <br>";
  187. }
  188. }
  189.  
  190. ?>
  191.  
  192. </body>
  193. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement