Results 1 to 10 of 10
  1. #1

    Default Problem with PHP MD5 Encryption


    Hey guys, im pretty new to PHP but has a background on C Programming. I have a really, really ridiculous problem. This is about the MD5 encryption which I use in a login page. I got the code from phpmyeasy and this is what the md5 encryption source code looks like:

    $encrypted_mypassword=md5($mypassword);
    $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$encrypted_mypassword'";
    $result=mysql_query($sql);
    This code is correct. But the problem is whenever I use the correct login details, it says my password is wrong. I have asked my friend who happens to be a pro at PHP and he says the code is correct. I have an old working PHP login page where the MD5 encryption works and I compared, this is what the code looks like:

    $mypassword=md5($mypassword);
    $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
    $result=mysql_query($sql);
    This code works, as you can see in the bolded part, I changed the variable $encrypted_mypassword to $mypassword. This works and it makes me wonder why $encrypted_mypassword doesnt work with it. Does anyone have a clue why is this happening?

    I have checked everything from my databases and even initiated $encrypted_mypassword at the start of the code but still it wont work.

  2. #2
    Yes, your codes are fine. really.

    Probably you have problem with your conding conventions or nameing convetions. Maybe the name was declared in a global scope or used somewhere?

    Isolate your codes.

    Maybe you can do like this..
    $sql="SELECT * FROM ".$tbl_name." WHERE username='".$myusername."' and password='".$encrypted_mypassword."' ";

    Try the concatenation.
    Last edited by dodie; 08-12-2009 at 10:12 PM.

  3. #3
    Bai, have you checked if ang md5ed value ang musulod sa database? Try pud e echo ang value sa variable. I see nothing wrong with the codes above.
    Last edited by Dondon; 08-12-2009 at 10:16 PM.

  4. #4
    Quote Originally Posted by dodie View Post
    *snip*
    Thanks for the try bro but it didn't work :\

    I tried any variable name, but still it wont work. I think that solves the naming convention but then i'll take that into consideration.
    Quote Originally Posted by Dondon View Post
    Bai, have you checked if ang md5ed value ang musulod sa database? Try pud e echo ang value sa variable. I see nothing wrong with the codes above.
    Ok raman ang md5ed value don. I'll try echoing the variables nya.

  5. #5
    I'm not sure pud ha if this can solve your problem, kay ana man ka na mu work ang 2nd code (using $mypassword instead of $encrypted_mypassword), but dili kaha problema na sa data type? Try setting it to varchar(100) basin dili ra masigo hehehe.

  6. #6
    Finally found the problem, I echoed the variables and they're correct. The problem was here:

    $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$encrypted_password'";
    $result=mysql_query($sql);
    This is the part where the password is compared to the database. In the bolded area is $encrypted_password and before i solved it, that was $mypassword. That was the reason why the CGI only works with $mypassword. LOL yeah, my bad. Thanks for the effort guys

  7. #7
    LOLOL. Need more coffee 'tian

  8. #8
    Probably yeah, kanina pa kong buntag nag-sige ug experiment diri. Didn't notice duha diay kabuok ang kato nga code na akong gi-quote. Oh well, problem solved.

  9. #9
    ok na diay.. )
    Last edited by emailroy2002; 08-13-2009 at 12:20 AM.

  10. #10
    amazing.. the word "my" lang ang problem. ayos ah.. I'm picking up something about PHP and mySQL. bai, post pa mo mga problems. para pud makabrain storm ta. At least makasabot ang mga tao na interesado ug programming.

  11.    Advertisement

Similar Threads

 
  1. Help with PHP code problem
    By senpai91 in forum Websites & Multimedia
    Replies: 3
    Last Post: 11-13-2012, 10:38 AM
  2. Problem with your Symbian Cellphone Software?
    By Seņor Joze in forum Gizmos & Gadgets (Old)
    Replies: 421
    Last Post: 08-28-2010, 05:15 PM
  3. What Is The Problem With The Philippines and Your Solution?
    By slimer in forum General Discussions
    Replies: 58
    Last Post: 06-24-2008, 08:09 AM
  4. Problem with my rs mmc
    By jungie in forum Gizmos & Gadgets (Old)
    Replies: 1
    Last Post: 01-19-2006, 02:13 PM
  5. Problem With Gunbound's TCP,UDP Port
    By endofall in forum Software & Games (Old)
    Replies: 3
    Last Post: 08-25-2005, 09:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top