Skip to content

Instantly share code, notes, and snippets.

Created June 9, 2013 01:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/5737315 to your computer and use it in GitHub Desktop.
Save anonymous/5737315 to your computer and use it in GitHub Desktop.
Simple user auth
<html>
<head>
</head>
<body>
<?php
if (!isset($_POST['username']) OR !isset($_POST['password']) OR empty($_POST['username']) OR empty($_POST['password'])) {
echo "Please login:";
echo '<form method="POST">';
echo 'Username: <input type="text" name="username">';
echo 'Password: <input type="password" name="password"></br>';
echo '<input type="submit" value="Login">';
echo '</form>';
}
else {
$username = $_POST['username'];
$password = md5($_POST['password']);
try {
$pdo = new PDO('mysql:host=localhost;dbname=userauth', 'root', '');
}
catch(PDOException $e) {
echo 'ERROR:' . $e->getMessage();
}
$sql="SELECT * FROM userinfo WHERE username =:username AND password=:password";
$pds= $pdo->prepare($sql);
$query_params = array(
':username' => $username,
':password' => $password
);
$pds->execute($query_params);
$row = $pds->fetch(PDO::FETCH_ASSOC);
$result = count($row);
if ($result == 3) {
echo "User access granted, your username is $row[username] </br>";
echo "Your associated email is $row[email] </br>";
}
else {
echo "Access denied!";
}
}
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment