TheQuack45

PHP login code

Sep 25th, 2014
635
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.43 KB | None | 0 0
  1. $nick = $_POST['userName'];
  2.             $pass = $_POST['passWord'];
  3.             // Of course replace all the foo stuff with actual info, it does connect to the database correctly
  4.             $dsn = "mysql:dbname=foo;host=foo";
  5.             try {
  6.                 $dbh = new PDO($dsn, "foo", "foo");
  7.             } catch (PDOException $e) {
  8.                 echo "Connection failed: ".$e->getMessage();
  9.             }
  10.            
  11.             if (isset($_POST['submitButton'])) {
  12.                 if ($nick == "" && $pass == "") {
  13.                     echo "<p style=\"text-align:center;display-style:block;margin-left:auto;margin-right:auto;margin-top:0px;font-size:18pt;\">Username and password not entered</p>";
  14.                 } else if ($nick == "") {
  15.                     echo "<p style=\"text-align:center;display-style:block;margin-left:auto;margin-right:auto;margin-top:0px;font-size:18pt;\">Username not entered</p>";
  16.                 } else if ($pass == "") {
  17.                     echo "<p style=\"text-align:center;display-style:block;margin-left:auto;margin-right:auto;margin-top:0px;font-size:18pt;\">Password not entered</p>";
  18.                 } else {
  19.                     $loginQuery = $dbh->query("SELECT `PASS` FROM `USER` WHERE `NICK` = '".$nick."'");
  20.                     $loginQueryArr = $loginQuery->fetchAll();
  21.                     $loginQueryArrActual = var_dump($loginQueryArr);
  22.                     if (password_verify($pass, $loginQueryArr['PASS'])) {
  23.                        
  24.                     } else {
  25.                         echo "<p style=\"text-align:center;display-style:block;margin-left:auto;margin-right:auto;margin-top:0px;font-size:18pt;\">Username/password does not match that on file</p>";
  26.                     }
  27.                 }
  28.             }
Advertisement
Add Comment
Please, Sign In to add comment