开发者

MySQL chops off characters from md5 password

I'm developing a website locally using XAMPP. There is a registration page in which I save the password, after encrypting it with MD5, to a MySQL database. The problem is that when I try to log in, I'm unable to. I discovered that the password was the problem. I checked the database and compared the MD5-ed password with the one I logged in with (I just echoed the MD5 hash of the password onto the page to compare). I found that the one in the database was shorter than the one echoed. My conclusion was that MySQL was chopping off some characters at the end of the hash. What should I do? I know it has to do with some settings on MySQL but I need help.

As at now, I have to use subs开发者_运维百科tr function on the hash in the registration and login processes so as to be able to log in.


If the column length is causing the problem, alter the column to accept a longer length. MD5's are always 32 hex digits, so VARCHAR(32) would be a good option.


It depends by the length of the value in the database ... check your field in the database and verify that his type is atleast something like a varchar(32)

To fix it you can use a query like that

ALTER TABLE Example
 MODIFY password  varchar(32)  

or use the phpMyAdmin interface

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜