【发布时间】:2016-10-29 17:59:34
【问题描述】:
我尝试了解 form、password_hash 和 verify 是如何工作的。这是我写的简单代码。 我得到的结果是“无效密码”
我错过了什么?
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="pwd">
Password:
<table>
<tr>
<td><input name="passwd" type="text"/></td>
</tr>
<tr>
<td align="center"><br/>
<input type="submit" name="submit_pwd" value="hash"/>
</td>
</tr>
</table>
</form>
<?php
$passwd = $_POST['passwd'];
echo "Password : <BR>".$passwd."\n <BR>" ;
echo "Hash : <BR>".$hash = password_hash($passwd, PASSWORD_DEFAULT). "\n <BR>";
if (password_verify($passwd, $hash)) {
echo 'Password is valid!';
} else {
echo 'Invalid password.';
}
?>
</body>
</html>
【问题讨论】:
-
你的 PHP 版本是什么? (
echo PHP_VERSION;)
标签: php html password-hash