Last active
August 29, 2015 14:21
-
-
Save Luguan/b2a02b3bbe093c0dd89c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php | |
session_start(); | |
$dbh = new PDO('mysql:host=julkalender3d.se.mysql;dbname=julkalender3d_s', 'julkalender3d_s', 'amax3Ds'); | |
if(isset($_POST['username']) && isset($_POST['password'])) | |
{ | |
$error = login($_POST['username'], $_POST['password']); | |
if ($error) { | |
echo "Could not login ".$error; | |
echo $username ." hej ". $password; | |
} | |
else { | |
$_SESSION['loggedIn'] = true; | |
$_SESSION['admin'] = $row['Admin']; | |
header('Location: dagligtArbete/hem.php'); | |
} | |
} | |
function login($username, $password) { | |
global $dbh; | |
$loginStmt = $dbh->prepare('SELECT * FROM Users WHERE Namn = :username'); | |
$loginStmt->bindValue(':username', $username); | |
$loginStmt->execute(); | |
$row = $loginStmt->fetch(PDO::FETCH_ASSOC); | |
if(!$row) | |
return "Account not found"; | |
if(!password_verify($password, $row['Password'])) | |
return "Incorrect password"; | |
return null; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment