Guest User

Untitled

a guest
Jun 28th, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.95 KB | None | 0 0
  1. <?php
  2.     session_start();
  3.     // Connecting to the database
  4.     include 'mysql.php';
  5.    
  6.     // Sanitize input to prevent injections
  7.     $username = $_POST['username'];
  8.     // Encrypt the password so real input isn't stored in the cookie
  9.     $password = $_POST['password'];
  10.     $salt = $username . $password;
  11.     $hash = hash('sha256', $salt . $password);
  12.    
  13.     // Perform the SQL queries
  14.     $db = new mysqli($host, $username, $password, $database);
  15.  
  16.     if (!$db) {
  17.         echo "Can't connect to MySQL Server. Errorcode: %s\n". mysqli_connect_error();
  18.         exit;
  19.     }
  20.  
  21.     $login = $db -> stmt_init();
  22.    
  23.    
  24.  
  25.     $login->prepare("SELECT * FROM $login_table WHERE `username` = ?, `password` = ?");
  26.     $login->bind_param('ss', $username, $password);
  27.  
  28.     if($login->execute();) == 1) {
  29.             $_SESSION["valid_user"] = $_POST["username"];
  30.             $_SESSION["valid_time"] = time();
  31.             $_SESSION["valid_pw"] = $password;
  32.             Header("Location: admin.php");
  33.         } else {
  34.             die("Invalid login.");
  35.             }
  36. ?>
Add Comment
Please, Sign In to add comment