开发者

Creating a custom md5 user id from form information

I am creating a form that will capture all of the form data and store it in a database, what I would like to do is use some of the form data to create a custom md5 user id to prevent multiple entries, I know that this is most probably not the most ideal way of doing i开发者_如何转开发t, so if there is a better way of creating a unique md5 uid that I can use for each user, please enlighten me.

I have considered just using a random number and checking the database against the email and first name, but I am curious to see if there is a better way of doing it.

Thanx in advance!


Wait ... you are wanting to use a unique MD5 to create a user id? ... why not use an auto_increment integer field? Each time the INSERT is run, it will be increased by 1 therefore always being unique. And since it is an integer, if you are doing any searches against it it would be a lot faster.


You can let MySQL do the work for you using "UNIQUE". Assuming you have a table user_data(user_data_id, name, text, content, date) and want name and text to be UNIQUE as a tuple:

CREATE user_data (
   user_data_id INTEGER,
   name VARCHAR(50),
   text TEXT,
   date DATE,
   PRIMARY_KEY(user_data_id),
   UNIQUE(name,text)
);


I assume you mean you want to avoid having duplicate entries by the same person.

You should probably check the database for the input's email + firstname + lastname, after normalizing them with strtolower() and removing spaces etc.

Apart from that you can't know for sure if the person entering data in the form has done it before. You can't safely rely on the ip being the same due to proxies and gateways, or even the computer being the same (shared computers). If you are aggressive on those 2 fronts you'll probably get alot of frustrated legitimate users that can't use your system.

Your best bet is to assume your database has duplicate entries and then decide what to do with them. Either flag the ones not being used, if they're accounts on the system have some intelligence to check if they're duplicates based on their behavior.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜