Page 1 of 1
username and password validation
Posted: Wed Oct 29, 2003 5:59 pm
by mydingding
i am working on a validation page that will validate a username and a password, coming from the login page. i have gotten the information to transfer pages but need some help on validating.
would i put the valid usernames and passwords in an array?
Posted: Wed Oct 29, 2003 6:13 pm
by Gen-ik
The best way would be to store the usernames and passwords in a database and check against that..... but as you're new to PHP let's start with something a bit more basic.
After you have sent the username and password to a page for validation you might use something like this.....
Code: Select all
<?
$un = $_GET["username"];
$pw = $_GET["password"];
$accounts["Bob"] = "bobpassword";
$accounts["Jim"] = "jimbo2000";
$accounts["Sarah"] = "doggies";
$account_exists = false;
foreach($accounts as $username => $password)
{
if($username == $un && $password == $pw) $account_exists = true;
}
if($account_exists)
{
// Things are good. Code goes here
}
else
{
// The username and/or password is wrong. Code goes here
}
?>
Posted: Wed Oct 29, 2003 6:13 pm
by volka
or in a database or a ldap-directory or ...

start with
http://www.evilwalrus.com/search.php?ca ... arch=login
Posted: Thu Oct 30, 2003 4:18 am
by Fredix
Though I haven't done all that login stuff and validating myself yet, I would like to give you a tipp:
store passwords as md5sums in your database (that is how this board stores them, too) this way no one can logon as someone else even if he hacked your db!