954,597 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

help

Ok, so i have a log in and a register script. Today i put a md5() encoding mechanism on it so it encodes the password when it is sent to the database. Now, how do i encode all of the passwords that were already inside the database? if anybody could help i would be extremely appreciative

tcollins412
Junior Poster
139 posts since Dec 2010
Reputation Points: 10
Solved Threads: 3
 

Just run a query to update them:

UPDATE table SET password_column = MD5(password_column)

Don't forget to backup first, just in case...

pritaeas
Posting Expert
Moderator
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

it worked but now it wont let me or anybody else log in. Im using this script:

<?php
include'dbconnect.php';

$tbl_name="*******"; 

$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
$cleanpass=md5($mypassword);

$myusername = stripslashes($myusername);
$cleanpass = stripslashes($cleanpass);
$myusername = mysql_real_escape_string($myusername);
$cleanpass = mysql_real_escape_string($cleanpass);

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$cleanpass'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

if($count==1){
session_register("myusername");
session_register("mypassword");
header('location:memberspage.php');
}
else {
echo "Wrong Username or Password";
}
?>
tcollins412
Junior Poster
139 posts since Dec 2010
Reputation Points: 10
Solved Threads: 3
 

What if you do

SELECT * FROM $tbl_name WHERE username='$myusername' and password=MD5('$mypassword')
pritaeas
Posting Expert
Moderator
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

still wont work

tcollins412
Junior Poster
139 posts since Dec 2010
Reputation Points: 10
Solved Threads: 3
 

echo out the query:

echo $sql;


This will stop any header(), but that's ok for now.

Check the screen output. Copy the output and paste into the SQL (or Query) box in your fave MySQL GUI (e.g. phpMyAdmin, Navicat, SQLyog, etc). See what happens.

//EDIT

Hold on! Silly question, but are md5-ing twice? Once with php and then again with SQL? If so, you'll not get a match.

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,796 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

I do not understand your question or what u want me to do with the echo

tcollins412
Junior Poster
139 posts since Dec 2010
Reputation Points: 10
Solved Threads: 3
 

OK forget the duplicate md5, it wasn't working before pritaeas suggested the switch from php md5 to MySQL MD5. Anyway,

1. echo the query as I mentioned.
2. copy the output from the screen.
3. open phpmyadmin.
4. navigate to the 'SQL' pane.
5. paste the query from the clipboard to the pane.
6. press the 'go' button.
7. look at the results or any error message.

sql.png

Attachments sql.png 61.49KB
diafol
Rhod Gilbert Fan (ardav)
Moderator
7,796 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: