<html>
<a href="/">
<button>
Home
</button>
</a>
<br>
Login:
<br>
<br>
<form method="POST">
Username
<br>
<input placeholder="Username" type="text" name="Username">
<br>
<br>
Password
<br>
<input placeholder="Password" type="password" name="Password">
<br>
<br>
<button> Login </button>
</form>
<?php
$pass_detect = False;
$user["username"] = $_POST["Username"];
$user["password"] = $_POST["Password"];
if (!empty($user["username"]) and !empty($user["password"])) {
if(strpos(file_get_contents("secure/users.txt"),$user["username"]) !== false) {
$search = $user["username"];
$lines = file('secure/users.txt');
$line_number = false;
while (list($key, $line) = each($lines) and !$line_number) {
$line_number = (strpos($line, $search) !== FALSE) ? $key 1 : $line_number;
}
$line_number = $line_number-1;
$lines = file('secure/pass.txt');
$pass_detect = $lines[$line_number];
if ($pass_detect == $user["password"]) {
echo "Login Successfull!";
} else {
echo "Invalid Password!";
}
} else {
echo "Invalid account";
}
} else {
echo "Username or Password is empty!";
}
?>
<br>
<br>
Don't have an account?
<br>
Join the development team.
<br>
<a href="request-dev.php">
<button>
Sign up
</button>
</a>
</html>
On line 39, I'm detecting 2 values, and even though they're the same, it still outputs "false". I also tried it with "===", however it still outputs the same result. I'm curious as to why those 2 values do not match, even though when I echoed them, they outputed the same value.
I was expecting the if satement, on line 39, to output "true"!
CodePudding user response:
$pass_detect = trim($pass_detect);
Turns out that $pass_detect
had an unnecessary space in it.
Thanks to:
@aynber
@Arleigh Hix
for helping me answer my question! -- Stack overflow says that I can accept my answer in 2 days.
CodePudding user response:
switch ($var) { case "abc": case "def": case "hij": echo "yes"; break; default: echo "no"; }