Advertisement
Guest User

Untitled

a guest
Apr 18th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.04 KB | None | 0 0
  1. <?php
  2.  
  3. $db_host = 'localhost';
  4. $db_user = 'root';
  5. $db_pass = null;
  6. $db_name = 'simple';
  7.  
  8. $conn = new mysqli($db_host, $db_user, $db_pass, $db_name);
  9.  
  10. if ($conn->connect_error) {
  11.     die('Connection failed: ' . $conn->connect_error);
  12. }
  13.  
  14. if ($_SERVER['REQUESTED_METHOD'] == 'POST') {
  15.     $name = $_POST['name'];
  16.     $password = $_POST['password'];
  17.  
  18.     $sql = "SELECT name, password FROM users WHERE name = '" . $name . "' LIMIT 1";
  19.  
  20.     if ($result = $conn->query($sql);) {
  21.         while ($user = $result->fetch_assoc()) {
  22.             if (password_verify($password, $user['password'])) {
  23.                 echo 'Sekmingai prisijungete';
  24.             } else {
  25.                 echo 'Blogi duomenys';
  26.             }
  27.         }
  28.  
  29.         $result->free();
  30.     } else {
  31.         echo 'Blogi duomenys';
  32.     }
  33. }
  34.  
  35. ?>
  36.  
  37. <!DOCTYPE html>
  38. <html>
  39. <head>
  40.     <title>Login</title>
  41. </head>
  42. <body>
  43.     <form method="POST">
  44.         <label for="name"></label>
  45.         <input id="name" type="text" name="name">
  46.        
  47.         <label for="password"></label>
  48.         <input id="password" type="password" name="password">
  49.        
  50.         <button>Login</button>
  51.     </form>
  52. </body>
  53. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement