First things first... having the password on a seperate line makes things far more difficult. Why not seperate it with username : password?
Then you could just do something like this...
if (isset($_POST['user']) && isset($_POST['pass'])) {
$userarray = file("users.txt");
foreach($userarray as $user) {
list($valid_username,$valid_password) = explode(":", $user);
if ($_POST['user'] == $valid_username && $_POST['pass'] == $valid_password) {
// Register session
break;
}
}
}
I'm also always paranoid with using basic for loops and avoid them at all costs.
As for problems with your original code, I would guess its the undefined $user and $password variables. If register globals is on, it should be $pass not $password