Click to See Complete Forum and Search --> : multi passwords


cybercampbell
10-15-2004, 03:48 AM
Hi all

I'm using this to password a part of my site my site:


include("pass.cgi");
if ($_POST['txtUsername'] != $username || $_POST['txtPassword'] != $password)
{
// login form, input txtUsername & txtPassword
}
else {
// protected content
}


and pass.cgi look like this:


$username = "user";
$password = "pass";


this works fine but what I need to do is have more than one username and password.

e.g.


$username = ("user1","user2","user3","user4");
$password = ("pass1","pass2","pass3","pass4");


or:


$username = "user1";
$password = "pass1";
.$username = "user2";
.$password = "pass2";
.$username = "user3";
.$password = "pass3";


Cheers
Chris

avarel007
10-15-2004, 03:53 AM
you can create a database for user login.

cybercampbell
10-15-2004, 03:57 AM
The friend I'm doing this for has no access to a database...only PHP.

Thanks Chris

avarel007
10-15-2004, 04:15 AM
Than you can create an array.

Example;


Array is like this:
$username[0]="login1"; $pass[0]="pass1";
$username[1]="login1"; $pass[1]="pass1";
$username[2]="login1"; $pass[2]="pass1";
$username[3]="login1"; $pass[3]="pass1";

login control part:
for($i=0;$i<4;$i++)
{
if($_POST["username"]==$username[$i] & $_POST["password"]==$pass[$i])
{
$login=1;
break;
}
}
if(@$login==1)
{
//protected page
}
else
{
//login form
}

yuna
10-15-2004, 07:46 AM
If his system can support Berkeley dbm-style databases (essentially files containing hashed name=value pairs), you might want to look at http://www.php.net/manual/en/ref.dba.php.

NogDog
10-15-2004, 08:42 AM
Something simple with a little bit of security would be to put the username/password pairs in a include file in a directory not in the public_html area, for example:

/home/webmaster/users.txt

<?php
$users = array(
"username1" => "password1",
"username2" => "password2",
"username3" => "password3",
"username4" => "password4",
"username5" => "password5"
);
?>


/home/webmaster/public_html/login.php

<?
include "../users.txt";
if(array_key_exists($_POST['user'], $users) and
$users[$_POST['user']] == $_POST['password'])
{
# good login, proceed with processing
}
else
{
# error message
}
?>