Question about md5()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
WizyWyg
Forum Commoner
Posts: 92
Joined: Tue Aug 06, 2002 7:20 pm

Question about md5()

Post by WizyWyg »

Im trying to work on a script for authentication for administrator rights.

I have a user table in my db that contains these rows:
userid , username , password.

The password in the table has been encrypted using md5.

Im having trouble creating the script for logging in, and taking their non-md5 password and matching it up with to the one in the db.

Anyone has an example of making a simple login script using md5 for logging in?

Or a basic explanation on how to compare what is inputed by the user and compare it to the one in the db?
Shadough
Forum Newbie
Posts: 20
Joined: Tue Jun 04, 2002 9:11 pm

Post by Shadough »

if the password in the db is stored as md5

Code: Select all

// we have no auth as of now
$ok = false;

// if md5() value of supplied password = the db (md5) password then we have auth
if (md5($passwd) == $db_passwd) {
  /* the password matches */
  unset($ok);
  $ok = true;
}

if ($ok) {
  //auth successfull
} else {
  //auth failed
}
hth
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

OR, better yet, if your database is good, it should have an MD5 function built in.

SELECT rank FROM users WHERE username = 'username' AND password = MD5('password') AND status != 'banned'
Post Reply