introducing usernames #11
13
login.php
13
login.php
@ -3,14 +3,13 @@ session_start();
|
|||||||
$pdo = new PDO('mysql:host=localhost;dbname=usertable', 'usertable', 'password');
|
$pdo = new PDO('mysql:host=localhost;dbname=usertable', 'usertable', 'password');
|
||||||
|
|
||||||
if(isset($_GET['login'])) {
|
if(isset($_GET['login'])) {
|
||||||
$email = $_POST['email'];
|
$username = $_POST['username'];
|
||||||
$password = $_POST['password'];
|
$password = $_POST['password'];
|
||||||
|
|
||||||
$statement = $pdo->prepare("SELECT * FROM users WHERE email = :email");
|
$statement = $pdo->prepare("SELECT * FROM users WHERE username = :username");
|
||||||
$result = $statement->execute(array('email' => $email));
|
$result = $statement->execute(array('username' => $username));
|
||||||
$user = $statement->fetch();
|
$user = $statement->fetch();
|
||||||
|
|
||||||
//Überprüfung des Passworts
|
|
||||||
if ($user !== false && password_verify($password, $user['password'])) {
|
if ($user !== false && password_verify($password, $user['password'])) {
|
||||||
$_SESSION['userid'] = $user['id'];
|
$_SESSION['userid'] = $user['id'];
|
||||||
$_SESSION['email'] = $user['email'];
|
$_SESSION['email'] = $user['email'];
|
||||||
@ -18,7 +17,7 @@ if(isset($_GET['login'])) {
|
|||||||
$_SESSION['lastName'] = $user['lastName'];
|
$_SESSION['lastName'] = $user['lastName'];
|
||||||
die('successfull. go to: <a href="secure.php">secure page</a>');
|
die('successfull. go to: <a href="secure.php">secure page</a>');
|
||||||
} else {
|
} else {
|
||||||
$errorMessage = "somethings wrong (maybe wrong password or wrong email)<br>";
|
$errorMessage = "somethings wrong (maybe wrong password or wrong user)<br>";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -37,8 +36,8 @@ if(isset($errorMessage)) {
|
|||||||
?>
|
?>
|
||||||
|
|
||||||
<form action="?login=1" method="post">
|
<form action="?login=1" method="post">
|
||||||
E-Mail:<br>
|
Your Username:<br>
|
||||||
<input type="email" size="40" maxlength="250" name="email"><br><br>
|
<input type="text" size="40" maxlength="250" name="username"><br><br>
|
||||||
|
|
||||||
Your password:<br>
|
Your password:<br>
|
||||||
<input type="password" size="40" name="password"><br>
|
<input type="password" size="40" name="password"><br>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user