/    Sign up×
Community /Pin to ProfileBookmark

Hello,

So I designed a login & registration system for my website using PHP. Everything is fine, except I’m trying to get this “Change Password” working correctly.

In practice it works, but it doesn’t convert my new passwords to MD5. Can anyone tell me how to properly send an MD5 string to MySQL?

Here is the specific line (I think) that need to be converted to MD5:

[code=php]
$sql=mysql_query(“UPDATE members SET passwd=’$newpassword’ where login=’$username'”); [/code]

Here is my whole script:

[code=php]<?php

session_start();

$dbhost = localhost;
$dbuser = ”;
$dbpass = ”;

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die (‘Error connecting to mysql’);

$dbname = ‘db’;
mysql_select_db($dbname);

$username = $_POST[‘login’];
$password = $_POST[‘passwd’];
$newpassword = $_POST[‘newpassword’];
$confirmnewpassword = $_POST[‘confirmnewpassword’];

$result = mysql_query(“SELECT passwd FROM members WHERE login=’$username'”);
if(!$result)
{
echo “The username you entered does not exist”;
}
else
if($password!= mysql_result($result, 0))
{
echo “You entered an incorrect password”;
}
if($newpassword=$confirmnewpassword)
$sql=mysql_query(“UPDATE members SET passwd=’$newpassword’ where login=’$username'”);
if($sql)
{
echo “Congratulations You have successfully changed your password”;
}
else
{
echo “The new password and confirm new password fields must be the same”;
}
?>[/code]

Any suggestions?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@gvreJun 09.2011 — [code=php]$username = $_POST['login'];
$password = $_POST['passwd'];
$newpassword = $_POST['newpassword'];
$confirmnewpassword = $_POST['confirmnewpassword'];

if ($newpassword && $confirmnewpassword && $newpassword == $confirmnewpassword)
{
// passwords are same
$username = mysql_real_escape_string($username);
$newpassword = md5($newpassword);
$q = mysql_query("UPDATE members SET passwd='$newpassword' where login='$username'");
// ...
}
else
{
// ...
}[/code]
Copy linkTweet thisAlerts:
@Andrew977authorJun 10.2011 — Thanks!
×

Success!

Help @Andrew977 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...