PHP在foreach循环中查找密码

I have a very simple login script, it requires just a password and thats it. The user will attempt to login and when the user enters the wrong password the php script will append the password to a text file but first the script checks whether the password is already in the file and if it is, the script will then add 1 to the number of attempts in the file. My problem is i am trying to find a way to check every password and then add the password but not check each individual password and add the password right away. I am using a class file found at this website My code is below.

<!DOCTYPE html>
<html>
<head>
    <title>Website</title>
</head>
<body>
<form method="post" action="Assets/Scripts/PHP/Login.php">
    <table>
        <tr>
            <td>
                <label for="Password">Password:</label>
            </td>
            <td>
                <input type="password" name="password" placeholder="Password" id="Password" />
            </td>
        </tr>

        <tr>
            <td>

            </td>
            <td>
                <input type="submit" name="submit" value="Log In" />
            </td>
        </tr>
    </table>
</form>
</body>
</html>

Login.php

<?php
$Password = $_POST['password'];
$Submit = $_POST['submit'];

if(isset($Submit))
{
    if($Password != '' && $Password == 'Password')
    {
        session_start();
        $_SESSION['Login'] = 'True';
        $Login = $_SESSION['Login'];
        if(isset($Login))
        {
            header("location:../../../main.php");
        }
        else
        {
            header("location:../../../index.html");
        }
    }
    else
    {
        include("../../../MyTXT.php");
        $File = new MyTXT("../../Texts/Passwords.txt");
        foreach($File->rows as $Row)
        {
            if($Row != $Password)
            {
                $File->add_row(array($Password, "1"));
                $File->save();
            }
            else
            {

            }
        }
        echo 'The Password Is Incorrect';
        echo '<br />';
        echo '<a href="../../../index.html">Go Back</a>';
    }
}
else
{
    header("location:../../../index.html");
}

Txt File

Password:|:Attempts

Test:|:26

Test123:|:2

Test456:|:5

Is there a specific reason you're using the code from the link? It looks like a LOT of code for what is a simple task.

Try these:

Read contents of the file into a string: http://php.net/manual/en/function.file-get-contents.php

Read contents of file into an array: http://php.net/manual/en/function.file.php

I'm still not exactly sure how you're checking if their password is correct, as your file contains incorrect passwords, however, a quick example (v quick..) of how to check for a string in a file:

$strPassword = '123test';
$strFilename = 'pass.txt';
$strFileContents = file_get_contents($strFilename);

if(strpos($strFileContents, $strPassword)) 
  {
   //$strPassword is there, log them in/whatever
  }
else
  {
    //password not there
  }

However if you want/need to use that script from that site, then in the downloads there are examples of how to use it. You should study those and write code with them, and if you are stuck, ask specific questions.