duangou2046 2012-03-17 19:34
浏览 22
已采纳

PHP / SQL:Un-md5一个字符串[重复]

Possible Duplicate:
Is it possible to decrypt md5 hashes?

I have a database to store usernames, passwords, emails, etc. If a user forgets his/her password, I will send it to their email account.

The problem is that I encrypt the password to md5 before I store it into my database. If the user's password is ABC, I store it in my database as 867dbd57e9ca9f808. I cannot send the user "867dbd57e9ca9f808" if they forget their password. I would need to send "ABC". However, that would require me to "un-md5" the string, which I don't think is possible.

  • 写回答

5条回答 默认 最新

  • dongzz4545 2012-03-17 19:37
    关注

    MD5 was designed to be hash, which is one way only, otherwise it would not be a hash. You should not send user his password, but give possibility to change it. You should generate a token, send link to change password to user's mail with token in GET parameter. If user change the passwords remove the token. Also, you should remember that token must have expiry time.

    Something like:

    myurl.com/passwordrecovery?token=someGeneratedToken
    

    In database, you can look for token, and get user id. So for example, your table structure can look like:

    user_id | token | expiry_time
    

    If you would keep only tokens and expiry time in database, don't do this. Associate token with user, otherwise user can request password change, and he will get following link(Don't do this):

    myurl.com/passwordrecovery?token=token&user_id=number
    

    This way he can change someone else's password by replacing user_id. And get access to his account. Expiry time should not be longer than 24 hours.

    Important

    Don't use plain md5, it's easy to crack. Use pbkdf2 for example.

    PHP implementations: PHP-Crypt-Lib, Pbkdf2 by inanimatt

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决