Compare two strings from line in txt file
<p>I have a txt file which contains a few pieces of information which include, amoung other things, a name a password. From a form submission I need to check if the password matches the name, I really suck at txt files, but this works:</p>

<pre><code>    function checkPassword($password, $username){
        $userinfo = file_get_contents(USER_INFO); 
        $uniqueinfo = explode("-", $userinfo);
        if (in_array($password, $uniqueinfo) &amp;&amp; in_array($username, $uniqueinfo)) {
            return true;
        } else {
            return false;
        }
    }
</code></pre>

<p>Now, as you've probably guessed this will return true as long as a valid username and password are found, even if they don't belong to the same account. So you can get this to return true if you enter a password from a different account. Not good. So, I tried:</p>

<pre><code>    function checkPassword($password, $username){
        $userinfo = file_get_contents(USER_INFO); 
        foreach($userinfo as $uniqueinfo) {
            $uniqueinfo = explode("-", $uniqueinfo);
            if (in_array($password, $uniqueinfo) &amp;&amp; in_array($username, $uniqueinfo)) {
                return true;
            } else {
                return false;
            }
        }
    }
</code></pre>

<p>But this just returns false even with valid credentials. Not sure where I'm going wrong here so any help would be appreciated. Thanks.</p>
