Advertisement
Moravetskyi

Untitled

Sep 10th, 2014
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. <?php
  2.  
  3. $connect = mysqli_connect('localhost', 'root', '12345', 'bugs');
  4. $result = mysqli_query($connect, "Select * from user");
  5.  
  6. if (mysqli_connect_errno()) {
  7. echo "Failed to connect to MySQL: " . mysqli_connect_error();
  8. }
  9.  
  10. //protect from html
  11. $user_login = htmlspecialchars($_POST['login']);
  12. $user_password = htmlspecialchars($_POST['pass']);
  13.  
  14. //protected from sql
  15. $login = mysqli_real_escape_string($connect, $user_login);
  16. $password = md5(mysqli_real_escape_string($connect, $user_password)).$login;
  17.  
  18.  
  19. //Log IN
  20. if (isset($_POST['login_b'])&& strlen($login)<25 && strlen($password)<25) {
  21.  
  22. $query = "Select * from user where login='$login' and password='$password'";
  23. $result = mysqli_query($connect, $query);
  24. $myrow = mysqli_fetch_assoc($result);
  25.  
  26.  
  27. if (!empty($myrow)) {
  28. echo "<p align=center>Hello," . $myrow['login'] . "</p>";
  29. } else {
  30. echo "<p align=center>Wrong login: " . $user_login . " OR Password: " . $user_password . "</p>";
  31. }
  32.  
  33. }
  34.  
  35. //Registration
  36. if (isset($_POST['reg'])&& strlen($login)<25 && strlen($password)<25) {
  37. $result = mysqli_query($connect, "insert into user (login,password) values ('$login','$password')");
  38. }
  39. mysqli_close($connect);
  40. ?>
  41.  
  42.  
  43.  
  44. <html>
  45. <head>
  46. <title>LogIn</title>
  47. </head>
  48. <body>
  49.  
  50. <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
  51. <table align="center">
  52. <tr>
  53. <td><b>Login:</b></td>
  54. <td>
  55. <input type='text' name='login'>
  56. </td>
  57. </tr>
  58.  
  59.  
  60. <tr>
  61. <td><b>Password:</b></td>
  62. <td>
  63. <input type='text' name='pass'>
  64. </td>
  65. </tr>
  66.  
  67.  
  68. <tr>
  69. <td align="center" colspan='2'>
  70. <input id="button" name="login_b" style=" width: 110px;height: 50px" type='submit' value="Log In">
  71. <input id="button" name="reg" style="width: 110px;height: 50px" type='submit' value="Registration">
  72. </td>
  73.  
  74. </tr>
  75.  
  76. </table>
  77. </form>
  78. </body>
  79. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement