Created
June 9, 2013 01:59
-
-
Save anonymous/5737315 to your computer and use it in GitHub Desktop.
Simple user auth
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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