There are better ways to store passwords (databases for example), but if you want it this way 😉
First you need to create your password.php file, which would not give out your passwords when asked by browser. I suggest somthing like
<?php /*
username#password
username2#password2
username3#etc.
*/ ?>
Then you can open this file in another script and read the values:
<?php
$lines=file("password.php");
$auth=false;
foreach ($lines as $line)
{
//to get rid of the first and last line
if ($line=="<?php/*" || $line=="*/ ?>") continue;
//divide username from password
list($user,$pass)=explode("#",$line);
if ($user == $_POST['username'] && $pass == $_POST['password']) $auth=true;
}
?>
To improve this a bit you could store passwords hashed. When adding a user you should write username and a result of md5($pass."somestring");
While checking the password change the second if-statement to:
if ($user == $_POST['username'] && $pass == md5($_POST['password']."somestring")) $auth=true;
This method will make it harder to break in even if someone gets the password.php file.
The last possibility is, that instead of using text file you could make an array of username as a key and password as value. Then, before writing to file use serialize() function. After reading from file you'll need unserialize(). See their description in php manual.