PHP, keep your account secure.

Create a secure Login form with a few rows of code.

Posted by Salvo Bertoncini

Wednesday 17th of August 2016

A secure Login is a must for code that build a website. With this few rows code, you can easily compare your hash password (e.g. saved in a Database) with the input password.

Language: PHP.

Difficulty: Easy.


//$dbpass = password_hash('abcd1234', PASSWORD_DEFAULT, ['cost' => 12]);
$dbpass = '$2y$12$SUpH3MymDVlHwzOfbk98feG3ykTT6R3GZ1JVjtTFrUPFlwJfFv4Zu';

if(!password_verify($_POST["password"], $dbpass))
echo 'OPS. Something went wrong :( <br>';
echo 'Ok ;) <br>';

<h2>Password test</h2>
<form action='password_crypt.php' method='post'>
<input type="text" placeholder="Insert password" name="password" ></input>
<input type="submit" value="Submit"></input>

See this esample on my GitHub repo.