Web Host Directory Forums

View original thread:  Password & User Login name check


Pages: 1 
chekeleke
Hey guys,

On my website which I am building. I will want my site to have a page where users can log on if they are registered. I need the page to be able to check if the username and password already exist ( Kinda username and password authentication). Please help if anybody knows how to or where to get a script or a tutorial on doing just that. The username and password must be ckecked against the one they registered which will reside in a database.

Thanks
Chekeleke
chin
Are you going to use ASP or PHP?

And what database are you going to use? MS SQL or MySQL?
chekeleke
hey chin,

I am going to use php and mysql
RefCom
That would be pretty simple... You would want to create a database with a table named members, and have two columns username and password.

On each page that users need to be authenticated on you use PHP to:

include ('auth.inc.php'); if (authuser($username,$password)) {

// page contents here

} else {
// you are not authorized.
}

In your auth.inc.php file you have:

function authuser($username,$password) {
connect_to_db
if ($form_password == mysql_result(mysql_query("select username,password from members where username='$form_username';"),0,"password")) {
// $password is correct

// set cookies called $username and $password

return 1;
} else {
// not a good password.

return 0;
}
}


Now your form that you authenticate with can post to any page in your scripts, and you just have two fields called form_username and form_password.

That should take care of it - simple little two minute script, from me to you with no obligation - just an example of how open-source is cool.
Return to Thread List