help with Md5 password code

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
me666
Forum Commoner
Posts: 87
Joined: Wed Oct 08, 2008 5:04 pm

help with Md5 password code

Post by me666 »

i have a table with info into about users for my site, people can join fine with md5 as i used an example to do that but i have added a few bits to it. I am trying to make it so you can update certain parts, i can allow people to update anything in th table now except their password.... i can have them update it but not with md5 meaning the new password wont work.... here is how i update without using md5...

Code: Select all

<?php
$name = $_SESSION[username];
?>
<form>New Password: <input type="text" name="pass" maxlength="50"><input type="submit" name="edit" value="OK"></form>
<?php mysql_query("update users set password='$pass' WHERE username = '$name'");
?>
any ideas on how to change this to encrypt the new password to md5?

you can get me on leo@leos-webby.xf-s.com
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: help with Md5 password code

Post by VladSun »

Use the native MySQL function MD5()
:)
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: help with Md5 password code

Post by pickle »

Strictly speaking, md5 is hashing (one way), not encryption (two way).
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
me666
Forum Commoner
Posts: 87
Joined: Wed Oct 08, 2008 5:04 pm

Re: help with Md5 password code

Post by me666 »

so ur saying to change it to...

Code: Select all

<?php
$name = $_SESSION[username];
?>
<form>New Password: <input type="text" name="pass" maxlength="50"><input type="submit" name="edit" value="OK"></form>
<?php mysql_query("update users set password='MD5($pass)' WHERE username = '$name'");
?>
???
this then changes the pass word but when i try tologin it says my password is incorrect :S i think i did try that.... im new to this lol but cnt figure it out
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: help with Md5 password code

Post by VladSun »

Look at the (single!) example found in the manual I've point it to you.
There are 10 types of people in this world, those who understand binary and those who don't
me666
Forum Commoner
Posts: 87
Joined: Wed Oct 08, 2008 5:04 pm

Re: help with Md5 password code

Post by me666 »

i wernt sure where you was on about with the example but i have got it now thanks, i looked into it with the md5() function you mentioned, i figured i must use that so tried a few different ways i thought it would work and found a way it would... my code now looks a little like this.....

Code: Select all

<form method="post"><label>New Password: <input type="password" name="new-pass" maxlength="32"></label><br>Are you sure you have entered the correct new password? <input type="checkbox" name="Sure" onclick = "document.getElementById('yes').disabled=false;"><br><input type="submit" id="yes" name="updatepass" value="Change Pass" disabled="true"></form>
       <?php 
       if(isset($_POST['updatepass'])){
       $md5_password = md5($_POST['new-pass']);
       mysql_query("update users set password='$md5_password' WHERE username = '$name'");}
 ?>   
Not sure if this is how you was trying to explain it, but it works ok and does the job.... i have other codes in there so that if ur not logged in you cant even access this page, and ive added a checkbox you need to tick before you can submit it.... thanks for your help :)
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: help with Md5 password code

Post by VladSun »

[quote="me666"]

Code: Select all

if(isset($_POST['updatepass']))
{
       mysql_query("update users set password=MD5('".mysql_real_escape_string($_POST['new-pass'])."') WHERE username = '$name'");
}
There are 10 types of people in this world, those who understand binary and those who don't
me666
Forum Commoner
Posts: 87
Joined: Wed Oct 08, 2008 5:04 pm

Re: help with Md5 password code

Post by me666 »

sorry i bet u can tell im new to php and mysql, first project this lol....
so if i just change mine to what you have put there, thats how it is supposed to be right?

thanks agen for all ur help :)
Post Reply