Hash password with PHP password_hash() function

Your password hash :  

 

Password :

If you used MD5 to hash a password and a fieldlength of 32 chars to store it, you have to change the fieldlength in the MySQL database to at least 60 chars.

More hash info ➠ PHP crypt()


<?php

if( isset($_POST['submit']) && $_POST['pass'] <> "") {
	
	$password = $_POST['pass'];
	
	$pw_hash = password_hash($password, PASSWORD_BCRYPT);

	if (password_verify($password, $pw_hash)) {
		$pw_valid = "Password is valid";
	} else {
		$pw_valid = "Password is <b>not</b> valid";
	}
	
	echo "<p>Your password : <code style='color: navy;'>" .
		$pw_hash . "</code></p>";

	echo "<p>" . $pw_valid . "</p>";

} else {

	echo "<p>Your password : <code style='color: navy;'>" .
		"&nbsp;" . "</code></p>";	

	echo "<p>&nbsp;</p>\n";

}

?>

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

	<p>Password : <input name="pass" /></p>
	
	<p><input type="submit" name="submit" value="submit" /></p>

</form>