Forum Moderators: coopster

Message Too Old, No Replies

one time password

i am a student looking for a better explanation

         

slimone

4:22 am on Oct 3, 2007 (gmt 0)

10+ Year Member



[webmasterworld.com...]

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]

PHP_Chimp

12:01 pm on Oct 3, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you dont want to use a database then you could use a text file however it may be more difficult.

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
}

whoisgregg

3:14 pm on Oct 3, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can also store an array of username/password combinations in the php script directly.

$valid = array(
'jane' => 'word',
'joe' => 'pass'
);
if( isset($valid[$_POST['username']]) && $_POST['password'] == $valid[$_POST['username']]){
// let them in
} else {
// dont let them in
}

joelgreen

4:02 pm on Oct 3, 2007 (gmt 0)

10+ Year Member



OP wants one time passwords. So password has to be deleted after used once. So extending script :)

------------- 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'
);