Results 1 to 6 of 6

Thread: md5() problem

  1. #1
    Join Date
    Aug 2007
    Location
    Malaysia
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default md5() problem

    Hi,guys! I have some user records in database which need to encrpyt their password by using md5().So, i write a piece of code to set passwords to encrypted value.

    PHP Code:
    <?php 
    include("dbconn.cfg"); 
    $tbl_name1 "member"
    $tbl_name2 "staff"
    $result1 mysql_query("SELECT * FROM $tbl_name1"); 
    $result2 mysql_query("SELECT * FROM $tbl_name2"); 

    while(
    $row mysql_fetch_array($result1)){ 
          
    $encrypted1 md5($row['password']); 
          
    mysql_query("UPDATE member SET password = '".$encrypted1."' WHERE 
                      `member_id` = '"
    .$row['member_id']."'"); 


    while(
    $row mysql_fetch_array($result2)){ 
          
    $encrypted2 md5($row['password']); 
          
    mysql_query("UPDATE staff SET password = '".$encrypted2."' WHERE 
                      `staff_id` = '"
    .$row['staff_id']."'"); 


    ?>
    After run the above script once,I noticed that passwords are being encrypted,then modified the login script to validate user typed password.
    with encrypted password

    PHP Code:
    $tbl_name1 "member"
    $tbl_name2 "staff"

    $select1 "SELECT * FROM $tbl_name1 WHERE 
                      email = '" 
    $_REQUEST['email'] . "' 
               AND password = '" 
    MD5($_REQUEST['password']) . "' "

    $select2 "SELECT name FROM $tbl_name2 WHERE 
                     email = '" 
    $_REQUEST['email'] . "' 
             AND password = '" 
    MD5($_REQUEST['password']) . "' "
    Well, the problem arise here is I can't login also when typing the correct password.

  2. #2
    Join Date
    Oct 2005
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    you have md5 capitalized
    Code:
    $tbl_name1 = "member";  
    $tbl_name2 = "staff";  
    
    $select1 = "SELECT * FROM $tbl_name1 WHERE  
                      email = '" . $_REQUEST['email'] . "'  
               AND password = '" . md5($_REQUEST['password']) . "' ";  
    
    $select2 = "SELECT name FROM $tbl_name2 WHERE  
                     email = '" . $_REQUEST['email'] . "'  
             AND password = '" . md5($_REQUEST['password']) . "' ";
    Hey new design new look, goto xudas for personal webdsign help.. (:

  3. #3
    Join Date
    Aug 2007
    Location
    Malaysia
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Not really. I have tried that before.

  4. #4
    Join Date
    Aug 2007
    Location
    Malaysia
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Problem resolved.It is about field length of password.I set it only for varchar(15),not really enough for hashed value

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    PHP is case-insensitive for function and variable names. I suggest using the MySQL function MD5() rather than the PHP one. It will neaten your code somewhat.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Case insensitive for functions; strictly case sensitive for variables, though.

    In this case, using it in mysql would be simpler, but it would result in less control, if you were to desire comparing the value later, etc. If you're not storing it in the php, though [as a varaible], then just go ahead and use the mysql function.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

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