Forum Moderators: coopster
the post is too old but you can find it there. basically i want to do the same thing but i would like to do it without a database.
is it possible to have a text file with a list of available passwords that would change every month.
i would use a database but i am not that far yet.
any help would be greatly appreciated. i am a graphic designer and if someone could halp id be more than glad to do something for you
[edited by: eelixduppy at 4:32 am (utc) on Oct. 3, 2007]
[edit reason] fixed link [/edit]
Are you after a single password for an area that anyone can use? Or do you want to be able to give individuals there own password then stop its use once they have used it?
How foolproof do you want your system? If it is only to stop average people then use a cookie to say that they have already accessed the page and not allow them access again. It wont stop those that know what they are doing but would be a lot easier.
If you are just going to pick a list of passwords that anyone can use, then you dont need an external file. Just put the list in your php code i.e.
$avail_passwords = array('letmein', 'pass2', 'pass3', 'etc');
if (in_array [uk3.php.net]($_POST['password'], $avail_passwords) {
// let them in
}
else {
// dont let them in
}
------------- login.php ---------------
include('passwords.php');
if( isset($valid[$_POST['username']]) && $_POST['password'] == $valid[$_POST['username']]){
// let them in
// remove password from array
unset($valid[$_POST['username']]);
// save new list to file
$f = fopen('passwords.php','w+');
fputs($f, '<'.'?'."php\n");
fputs($f, '$valid = array('."\n");
foreach($valid as $u => $p) {
if (isset($valid[$u]))
fputs($f, "'$u' => '$p'\n");
}
fputs($f, ');');
fputs($f, '?'.'>');
fclose($f);
} else {
// dont let them in
}
--------- passwords.php -----------------
$valid = array(
'jane' => 'word',
'joe' => 'pass'
);