Jump to content

[SOLVED] Im haveing trouble using md5 for a password check


Recommended Posts

ok....I made a registration screen that encodes the users password into md5 encryption and stores it into a database. Everything works alright with that....however..after that I made a login screen that asks for the username and the pw and compares it to what is stored in the DB. The problem with my coding is that Im haveing trouble taking the password that is typed into the login screen and converting it to the md5 BEFORE the comparison is made. Example:

ID USERNAME MD5 ENCRYPION (pw is 1234 btw) E-MAIL ADDRESS

1 1234 81dc9bdb52d04dc20036dbd8313ed055 1234@1234.com

 

I type in 1234 as the username, and 1234 as the password and it is comparing the pw of 1234 to md5 encryption of 81dc9bdb52d04dc20036dbd8313ed055 and comming back negative. if I use 81dc9bdb52d04dc20036dbd8313ed055 as the password it works but that kind of defetes the purpose. =o)~

 

I just cant seem to type the md5 part out right for recalling it. Can anyone help? Here is my code:

<?php
ob_start();
$host="localhost"; // Host name
$username="username"; // Mysql username
$password="password"; // Mysql password
$db_name="db_name"; // Database name
$tbl_name="members"; // Table name

mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='.md5($mypassword).'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);
if($count==1){
session_register("myusername");
session_register("mypassword");
header("location:logged_in.php");
}
else {
echo "Username or Password not registered!";
}

ob_end_flush();
?>

 

Thank you all!!!

this

 

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='.md5($mypassword).'";

 

should be

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='".md5($mypassword)."'";

 

try it out and tell me if it works

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.