I had written this hyper-simple login for a web page.
<?php $data= file_get_contents('pass.txt');
session_start();
if (isset($_SESSION['timeout'])) { if ($_SESSION['timeout'] + 20 < time()) { session_destroy(); } }
else { $_SESSION['pass']="" ; $_SESSION['timeout']=time(); }
if (isset($_POST['pass'])) {$_SESSION['pass']=$_POST['pass'] ; }
if(!empty($_SESSION['pass'])) {
$line = explode("\n", $data);
for($i = 0; $i<count($line); $i++) {
$item = explode("\t", $line[$i]);
if (password_verify($_SESSION['pass'], $item[0])) {
echo "Welcome! You're logged in " .$item[1]. "! <a href='index.php?logout=true'>logout</a>";
if(isset($_GET['logout'])) {unset($_SESSION['pass']); header('location: index.php');}
}
}
}
else {
echo '<form method="POST" action=""><input type="password" name="pass"><form>';
}
?>
It was based on a txt flatfile like this (password hashed + user list):
$2y$10$WocHepZlhnk7g9VjHIyeEuZgeMNOKq5GDimjyfDK6rSH929mgDJNi user
I'm now trying to migrate it to sqlite3. But I'm not very good at sqlite coding. Could you help me? Thanks XXX
Aucun commentaire:
Enregistrer un commentaire