PDA

View Full Version : Add column to user table?


high6
08-12-2009, 08:44 PM
How would you add an md5 of the username as a column to the user table? And how would you keep them synced?

Andrew Green
08-12-2009, 08:59 PM
ALTER TABLE user ADD COLUMN usernamehash CHAR(32);
UPDATE TABLE user SET usernamehash = MD5(username);

Although I'm not sure what purpose that could serve...

high6
08-12-2009, 09:10 PM
But what about when a user registers or when a users name is changed?

Lynne
08-12-2009, 09:21 PM
But what about when a user registers or when a users name is changed?
You would have to write a couple of plugins to write to/update the column at each of those times.

Andrew Green
08-12-2009, 09:24 PM
Are you sure you need this? It seems rather unnecessary.

SELECT MD5(username) FROM user WHERE userid = ___;

you can have a MD5 whenever you want it, without adding a column or having to worry about syncing.

high6
08-12-2009, 09:56 PM
Well I am provided an md5 of the username and I need to get the row in the user table with it.

Andrew would this be possible? SELECT * FROM user WHERE MD5(username)='hash'?