Skip to content

Instantly share code, notes, and snippets.

@CloudyWater
Created January 31, 2017 00:35
Show Gist options
  • Save CloudyWater/00fb381622d7b80df0ec95a2c67fc1a3 to your computer and use it in GitHub Desktop.
Save CloudyWater/00fb381622d7b80df0ec95a2c67fc1a3 to your computer and use it in GitHub Desktop.
<?php
$dsn = 'mysql:host=localhost;dbname=dbname';
$username = 'username';
$password = 'password';
$userlogin = $_GET['username'];
$passwordAttempt = $_GET['password'];
try
{
$dbh = new PDO($dsn, $username, $password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$statement = $dbh->prepare ("SELECT * FROM users WHERE username=:username;");
$statement->bindParam (':username', $userlogin);
$statement->execute();
$result = $statement->fetch(PDO::FETCH_ASSOC);
if (password_verify($passwordAttempt, $result['password']))
{
echo "Password Verified!";
}
else
{
echo "Invalid Username or Password";
}
}
catch (PDOException $e)
{
echo "Error: " . $e->getMessage () . "<br/>";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment