1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How show md5 password

Discussion in 'PHP' started by bobby9101, Jun 9, 2007.

  1. #1
    Hi, I am storing my users passwords in a database using md5, however I want users to be able to see their passwords.
    And since md5 is a "one way" encryption, how do I do this?
    I have seen websites be able to do it, do they not encrypt their users passwords?
     
    bobby9101, Jun 9, 2007 IP
  2. HypertextFever

    HypertextFever Peon

    Messages:
    158
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Correct, you can't decrypt md5 (under normal circumstances). They could have their users passwords unencrypted, or be using a two-way proprietary encrytption method.
     
    HypertextFever, Jun 9, 2007 IP
  3. bobby9101

    bobby9101 Peon

    Messages:
    3,292
    Likes Received:
    134
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Ok, thanks
    For now I will just stick with md5, maybe later I will write a little encryption function that can be decrypted
     
    bobby9101, Jun 9, 2007 IP
  4. InFloW

    InFloW Peon

    Messages:
    1,488
    Likes Received:
    39
    Best Answers:
    0
    Trophy Points:
    0
    #4
    As much as it seems great to show a user their password there are numerous security reasons not to. What happens if someone gets a hold of the users cookie? Well now they can just grab the password since it is given to them in a profile area or something of that nature. Also when changing crucial information such as a password the person doesn't even need to know the current password now since it's basically given to them.

    I'd stick with a md5 and no decryption for user convience on their password. If they forget their password just have a forgot password option so they can generate a new one. Saves the whole security problem all together.
     
    InFloW, Jun 9, 2007 IP
  5. stOx

    stOx Notable Member

    Messages:
    6,426
    Likes Received:
    130
    Best Answers:
    0
    Trophy Points:
    230
    #5
    I agree with the above post. MD5 is one way because one way is better and safer. It's best to just provide a method of changing the password.
     
    stOx, Jun 9, 2007 IP
  6. *louie*

    *louie* Peon

    Messages:
    48
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #6
    same here.

    You can send them an email with all details including the password at the time of registration if it makes you feel better so they could save it for later.
     
    *louie*, Jun 9, 2007 IP
  7. ZenOswyn

    ZenOswyn Peon

    Messages:
    50
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Yeah, like the others said I wouldn't use 2 way encryption. Stick to hashes, in fact, use more than one if you can to help avoid the rainbow crack methods.

    Can't hurt, jurt in case your DB is compromised, but your PHP isn't.
     
    ZenOswyn, Jun 9, 2007 IP
  8. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #8
    it's definitely a bad idea from a security standpoint.
     
    ansi, Jun 9, 2007 IP
  9. ErsinAcar

    ErsinAcar Peon

    Messages:
    201
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #9
    hi!
    you can use base64..
     
    ErsinAcar, Jun 9, 2007 IP
  10. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #10
    sure... he could. but is base64 secure? not in the least... i would recommend a sha1 hash. especially in a database environment.
     
    ansi, Jun 9, 2007 IP
  11. ErsinAcar

    ErsinAcar Peon

    Messages:
    201
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #11
    If he use it a hash word yes. He wanna show passwords to users.. it's not secure. not base64 :)
    if you encrypt the pass. with base64 and using a hash on this encrypted data. no one dencrypt that easily if don't know the hash ;)
     
    ErsinAcar, Jun 9, 2007 IP
  12. olddocks

    olddocks Notable Member

    Messages:
    3,275
    Likes Received:
    165
    Best Answers:
    0
    Trophy Points:
    215
    #12
    what you do if the user forgot password just reset the password and do a md5 and then update your database. send an email to user of new password.
     
    olddocks, Jun 10, 2007 IP
  13. KalvinB

    KalvinB Peon

    Messages:
    2,787
    Likes Received:
    78
    Best Answers:
    0
    Trophy Points:
    0
    #13
    changing a password is best done with a two step process.

    The first is the user requesting that the password be changed. When that happens the table with the password should be updated so there's a field with a unique id. That unique id should be e-mailed as part of a link to a password change page.

    http://www.mypage.com/pw.php?uid=343421efbd459

    Or whatever.

    The second step:

    When the user goes to the page you just check the uid to get the user id that is requesting the password change.

    The user can then enter in the new password and the table is updated.

    UPDATE accounts SET password = MD5($new_password), uid = "" WHERE uid = $uid AND length(uid) > 5

    The e-mail step makes sure that malicious users can't force a password reset. The update query takes care of making sure a user can't update their password without making another request.
     
    KalvinB, Jun 11, 2007 IP
  14. tswebdesign

    tswebdesign Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    You should continue using md5 or some other "one-way" encryption algorithm. If your users forget their passwords, use must request the email address they used when signing up for the service. If such an email is found within the databases, create a function to generate a six letter temporary password, encrypt such password, and enter it on the database associated with the email address entered. Then send an email to the email address stating that the password has been changed. Only the owner of the email address, knowing the password to access the email, will receive the new temporary password. This allows for an extra level of security.
     
    tswebdesign, Jun 11, 2007 IP
  15. ProgrammersTalk

    ProgrammersTalk Peon

    Messages:
    684
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #15
    ProgrammersTalk, Jun 14, 2007 IP
  16. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #16
    or write your own simple xor cipher ....

    
    <?
    function cipher( $text, $key )
    {
    	$k = 0 ;
    	$count = 0 ;
    	
    	while( $count < strlen( $text ) )
    	{
    		$text{ $count } = $key{$k} ^ $text{ $count };
    		$k = $k == strlen( $key ) ? 0 : $k++;
    		$count++;
    	}
    	return $text;
    }
    
    $keys = array( 
    	'5^QTWETW£$%egrgw%%',
    	'5409uewafaSCNSVJfdv',
    	'54adQWQDQE',
    	'56^£^^&%$^£$!%""',
    	'123!")($£_)"$£")"',
    	'!WDFGRAW$)(ASw3tr4)'
    );
    $strings = array(
    	'the first string',
    	'weekpass',
    	'aMo4eComPLicAtEdStrIng',
    	'JustWastingMyLifeNow',
    	'OneFromTheFinish',
    	'And Finally we\'re done'
    );
    foreach( $strings as $index => $string )
    {
    	$ciphered = cipher( $string, $keys[ $index ] );
    	$deciphered = cipher( $ciphered, $keys[ $index ] );
    	printf( 'String : %s<br />', $string );
    	printf( 'Key : %s<br />', $keys[ $index ] );
    	printf( 'Ciphered : %s<Br />', $ciphered );
    	printf( 'Base64 Ciphered : %s<Br />', base64_encode( $ciphered ) );
    	printf( 'Deciphered : %s<br />', $deciphered );
    	echo "<br />";
    }
    ?>
    
    PHP:
    or use an implementation of xtea or something like that ...... md5 has been around for a long time now, it's possible to dehash any md5 given time and processing power, and it can be a pain not being able to see passwords, while that's only a few lines of code, if whoever is hacking your database doesn't know what you're using to encrypt passwords, then it's void + you can use any length keys with any characters in ......
     
    krakjoe, Jun 14, 2007 IP
  17. fouadz

    fouadz Peon

    Messages:
    132
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #17
    MD5 is not an encryption but a hash.
    You cannot go from the hash to the original password.
    the only way is to brute force. I dont think it's the best way to do in your case.

    Take care.
     
    fouadz, Jun 14, 2007 IP
  18. mikey1090

    mikey1090 Moderator Staff

    Messages:
    15,869
    Likes Received:
    1,055
    Best Answers:
    0
    Trophy Points:
    445
    Digital Goods:
    2
    #18
    you could always store md5 and normal text. store md5 in cookies so its a little safer.
     
    mikey1090, Jun 14, 2007 IP
  19. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #19
    your cookies might be a bit more secure sure, but that leaves your database wide open and viewable to everyone is someone were to gain access to it. still not a good idea. just generate a random password for the and they can login and change it to something that they will remember. easy peasy all is well and nothing to worry about.
     
    ansi, Jun 14, 2007 IP