tags:

views:

128

answers:

8

ive got a forum and i allow user to delete their account.

and i want the users threads to still be there and the username to be shown, but i wonder one thing.

if a user is deleted (basically i just NULL their username and password in the table row but i leave everything else intact) and another user is registering the same username, then people will believe that the new user with the same username has created all the threads the previous user created.

or is it routine to not allow new users to pick those usernames who have been deleted?

what is best practice regarding deleting users?

+1  A: 

Add a DeletedDate column. If this column is NULL, then the user account is not deleted.

This way you are not deleting any data, and you can undelete the account later if you wish, with username, etc. intact.

RedFilter
+8  A: 

Add an extra column to your users table, called 'deleted' or similar. Default this to zero (false). When the user is "deleted", set this field to 1 (true). That way you won't run across any problems with users having duplicate usernames, as the original will be still present and linked to your existing posts etc.

richsage
but i should NULL the username and password field right? then they cant login
weng
No, in your login sequence you should compare the username/password combination against your database as normal. Then if the 'deleted' column for this user is zero/false, the user is able to login as normal. If it's 1/true, then you reject the login.
richsage
If you null the username field, what will you show in the forum threads where you need to mention this user?
naivists
my mistake, i meant i null the email and password field. cause they log in with their email. why shouldnt i null email and password and let it still be there?
weng
Because there's no need to. A user's ability to login is effectively determined by a) email/password being correct and b) their "deleted" field being false. If the deleted field is set to true, disabling their login, why would you need to bother nulling any other fields in this case?
richsage
+1  A: 

You should not actually delete users, just set a "deleted" flag on their records in database. If such flag is set, do not allow the user to log in. Also, show the user page with "user is deleted" on it. If you actually delete a record, you will have to decide, what to do with

  • forum posts the user has been authoring
  • replies made by the user
  • replies where someone mentions something said by the deleted user
  • private messages sent to/from this user

So, this would actually change the conversations people have had.

naivists
+3  A: 

I would keep a deleted field in the table as a boolean. Set it to true when the user leaves. Keep usernames unique.

Daniel A. White
A: 

The posts should be linked to user via an ID not by username so unless you reuse an ID, which you shouldn't, then you won't have this problem.

Paul Creasey
+1  A: 

If it's important to enable others to use the old username, you could change user's name into eg. Deleted User X - that way there would still be a connection between the user's posts (which could be important in some cases).

Grav
+1  A: 

If you keep the posts and the usernames you don't want to people to register the same username again. It will cause a lot of confusion. Typically you also make the username a unique key of the user table.

I would recommend letting the users delete their accounts completely if there are no associated posts or other activity. If there are associated posts the account is disabled and the posts marked as made by "Deleted user".

Then make it an administrative action to wipe the account and associated posts completely. This can be added to your regular maintenance tools.

pehrs
+1  A: 

You can even add an extra column in users table titled "uid" and generate new uid for every new user who registers.

Nikit Batale