Beispiel:
Code (ungetestet) :
PHP
<?php
session_start();
$username = "Stef";
$password = "1234";
$hash = "aeb319838893dndfnfnfnf";
if(isset($username) && isset($password)){
try{
//DB-Verbindung
$dbh = new PDO('mysql:host=localhost;dbname=registration', 'root', '');
$stmt = $dbh->prepare("SELECT userId, rank FROM users WHERE username = :username");
$stmt->execute(
array(
":username" => $username
)
);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
}catch( EXCEPTION $e){
echo "Fehler aufgetreten " . $e->getMessage();
exit(1);
}
if(password_verify($password, $hash)){
$_SESSION['userId'] = $row['userId'];
$_SESSION['rank'] = $row['rank'];
if($row["rank"] == "admin"){
header("LOCATION: /interface/admin/dashboard.php");
} else{
header("LOCATION: /interface/dashboard.php");
}
}
}
Alles anzeigen
Die DB-Tabelle würde dann so aussehen:
| userId | username | passwordHash | rank | |
| 1 | Stef | stef@gmail.com | aeb319838893dndfnfnfnf | admin |