Guest User

Untitled

a guest
May 7th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.06 KB | None | 0 0
  1. <?php
  2.  
  3. // If the form was submitted
  4. if (isset($_POST['username']) && isset($_POST['password']) {
  5.    
  6.     // Start the session
  7.     session_start();
  8.  
  9.     // Connect to the database
  10.     $db = new PDO("mysql:host=localhost;dbname=members;port=3306");
  11.  
  12.     // Encrypt the password - SIMPLE ENCRYPTION
  13.     $pass = md5(sha1($_POST['password']));
  14.  
  15.     // Check if the user and pass match
  16.     $query = $db->prepare("SELECT COUNT(*) FROM users WHERE username=? AND password=?");
  17.     $query->execute($_POST['username'], $pass);
  18.    
  19.     // If it does match
  20.     if ($query->fetchColumn() >= 1) {
  21.  
  22.         // Register session and redirect
  23.         $_SESSION['username'] = $_POST['username'];
  24.         header("location:members.php");
  25.  
  26.     }else{
  27.  
  28.         // Echo a message
  29.         die('Username or password is incorrect');
  30.  
  31.     }
  32.  
  33. }else{ ?>
  34.  
  35.     <html>
  36.  
  37.     <head>
  38.         <title>Login</title>
  39.     </head>
  40.  
  41.     <body>
  42.         <form method="post" action="login.php">
  43.         Username: <input type="text" name="username"><br>
  44.         Password: <input type="password" name="password"><br>
  45.         <input type="submit" value="Login">
  46.         </form>
  47.     </body>
  48.  
  49.     </html>
  50.  
  51. <?php } ?>
Add Comment
Please, Sign In to add comment