Advertisement
Guest User

Safest login

a guest
Apr 11th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.92 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <meta charset="UTF-8">
  5.         <title></title>
  6.     </head>
  7.     <body>
  8.         <?php
  9.         session_start();
  10.         include "funkcije.php";
  11.         if (isset($_SESSION['loggedin'])) {
  12.             header('Location: ./index.php');
  13.         }
  14.         ?>
  15.         <form method="POST" action="login.php">
  16.             <ul>
  17.                 <li>
  18.                     Username: <input type="text" name="username" >
  19.                 </li>
  20.                 <li>
  21.                     Password <input type="password" name="password" >
  22.                 </li>
  23.                 <li>
  24.                     <input type="submit" name="submit" value="Log In" >
  25.                 </li>
  26.             </ul>
  27.         </form>
  28.         <?php
  29.         if (isset($_POST['submit'])) {
  30.             if (!empty($_POST['username']) && !empty($_POST['password'])) {
  31.                 @$user = htmlspecialchars($_POST['username'], ENT_QUOTES, 'UTF-8');
  32.                 @$pass = htmlspecialchars($_POST['password'], ENT_QUOTES, 'UTF-8');
  33.                 $query = "SELECT * FROM `users` WHERE username='" . mysqli_real_escape_string($con, $user) . "'";
  34.                 if ($result = @mysqli_query($con, $query)) {
  35.                     while ($row = @mysqli_fetch_assoc($result)) {
  36.                         $sifra = $row['password'];
  37.                         if (password_verify($pass, $sifra)) {
  38.                             $_SESSION['loggedin'] = time().$user;
  39.                             $_SESSION['user'] = $user;
  40.                             header('Location: ./index.php');
  41.                         } else {
  42.                             die("Sifra nije dobra.");
  43.                         }
  44.                     }
  45.                 } else {
  46.                     echo "Nepostojeci korisnik.";
  47.                 }
  48.             } else {
  49.                 echo "Sva polja su obavezna";
  50.             }
  51.         }
  52.         ?>
  53.     </body>
  54. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement