テキストファイルからパスワードを読み取り、ユーザーが入力したパスワードと比較しようとしていました。しかし、どちらの単語もまったく同じように見えますが、私のスクリプトは別のことを言っています。
$user = $_POST['user'];
$pass = $_POST['pass']; //HTML form element with type="password"
$line;
$retrievedPassword = "";
$f = fopen("data/abc.log", "r");
// Read line by line until end of file
while(!feof($f)) {
$line = fgets($f);
if (startsWith($line, $user)) {
break; //password found
}
}
fclose($f);
$var = explode(":", $line);
$retrievedPassword = $var[1];
echo $pass." ".$retrievedPassword; // example: password password
if (strcmp($pass, $var[1]) == 0) {
header('Location: user.php'); //never the case
}else {
//header('Location: index.php');
}
function startsWith($haystack, $needle)
{
return !strncmp($haystack, $needle, strlen($needle));
}
パスワードは暗号化されていますか、またはそのようなものですか、またはこのコードが機能しないのはなぜですか?