【发布时间】:2013-04-11 22:31:50
【问题描述】:
我有一个 php 文件:
<?php
if (isset($_POST['submit'])) {
$file_name = 'hash.txt';
$user = md5($_POST['user']);
$password = md5($_POST['password']);
$handle = fopen('hash.txt',"r");
$read_file = file($file_name);
if ($user == $read_file[0] and $password == $read_file[1]) {
echo 'correct !';
} else {
echo 'incorrect !';
}
} else {
echo 'please input something';
}
?>
<body>
<form action="file_handle3.php" method="post">
User<input type="text" name="user"/><br/>
Password <input type="password" name="password"/>
<input type="submit" name="submit" value="submit"/>
</body>
文件 txt : hash.txt 第一行是 hello 第二行是 world
5d41402abc4b2a76b9719d911017c592
7d793037a0760186574b0282f2f435e7
我想比较用户输入的值并将它们转换为 md5,然后与 txt 文件中的比较。我不知道为什么我的代码即使我输入准确的值也不会输出正确的答案(用户:你好密码:世界)。对不起我的英语不好
【问题讨论】:
-
如果您的 .txt 文件中有哈希,那么您应该将您的 md5 哈希密码与文件的哈希值进行比较,即 md5($password) == $read_file[1]。也许如果您将它作为纯文本接收一次,然后比较哈希值就可以了。您也可以尝试检查 md5($_POST['password']) 输出是否与您的 .txt
标签: php