I am trying to understand how password_hash()
function works.
I have got this ultra-simplified php login (completely unsafe, just designed to learn) with four passwords chosen by me.
<?php
$data = file_get_contents('pass.txt');
if($_POST['pass']) {
$line = explode("\n", $data);
for($i = 0; $i<count($line); $i++) {
$item = explode("#", $line[$i]);
if($_POST['pass'] == $item[0]) {
echo "Welcome! You're logged in!";
}
}
}
else { echo '<form method="POST" action="">
<input type="password" name="pass">
<input type="submit">
<form>';
}
?>
and this pass.txt
, where the passwords are kept (.txt flatfile database):
passone
passtwo
passthree
passfour
Is it possible to add password_hash() function to my code?
I guess the php should be able to rewrite the database for this purpose, as this functions rewrites the passwords every time you login.
Thanks guys XXX
password_hash
creates a random salt. Don't subvert that, it's missing the point of salts. You just need to usepassword_verify
instead of==
.