为什么此代码散列为空? [英] Why does this code hash null?
本文介绍了为什么此代码散列为空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下代码传递用户名检查,但密码失败。
正如您所看到的,哈希值会被回显,但由于某些原因,它们会输出 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
,这是 sha256sum
/ dev / null
。由于密码似乎没有回应,我只能假设它不能得到POST,但为什么?
登录
< form action =dologinmethod =post>
用户名:< input type =textname =username>
密码:< input type =passwordname =password>
< input type =submit>
< / form>
dologin
if($ _POST [username] == $ actualusername){
//哈希密码
$ hashedpassword = hash('sha256',$ _POST [password]);
echo $ _POST [password];
echo $ hashedpassword;
if($ hashedpassword == $ actualpassword){
echo'< h2> Logged in< / h2>';
} else {
echo'< h2>密码错误< / h2>';
echo $ hashedpassword;
}
} else {
echo'< h2>不正确的用户名< / h2>';
}
解决方案
你有问题吗?
此外,您可以使用
isset($ _ POST [blabla])
测试该值是否设置在 $ _ POST中
中。
The following code passes on the username check, but fails on the password.
As you can see, the hashes are echoed, but for some reason, they output e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
, which is the sha256sum
of /dev/null
. As the password does not seem to echo at all, i can only assume it cannot get the POST, but why?
login
<form action="dologin" method="post">
Username: <input type="text" name="username">
Password: <input type="password" name="password">
<input type="submit">
</form>
dologin
if ( $_POST[username] == $actualusername ) {
// Hash the password
$hashedpassword = hash('sha256', $_POST[password]);
echo $_POST[password];
echo $hashedpassword;
if ( $hashedpassword == $actualpassword ) {
echo '<h2>Logged in</h2>';
} else {
echo '<h2>Incorrect password</h2>';
echo $hashedpassword;
}
} else {
echo '<h2>Incorrect username</h2>';
}
解决方案
Does closing the input tags solve you problem? Also, you can use
isset($_POST["blabla"])
To test if the value is set in $_POST
.
这篇关于为什么此代码散列为空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文