www.webdeveloper.com
Results 1 to 3 of 3

Thread: MySQL and MD5

  1. #1
    Join Date
    May 2011
    Posts
    14

    MySQL and MD5

    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:
    PHP Code:
    $sql=mysql_query("UPDATE members SET passwd='$newpassword' where login='$username'"); 
    Here is my whole script:

    PHP Code:
    <?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($result0)) 

    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"
    }  
    ?>
    Any suggestions?
    Last edited by Andrew977; 06-09-2011 at 02:21 PM.

  2. #2
    Join Date
    Apr 2010
    Posts
    88
    PHP Code:
    $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
    {
            
    // ...


  3. #3
    Join Date
    May 2011
    Posts
    14
    Thanks!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles