As a developer, how should a users deletion of their account from a website be handled?
In the case of someone guessing the users password and deleting their account, you would want to be able to reinstate the account, so deleting it instantly and fully can't be the answer.
On the other hand if you are sure you want to delete an account it would still be in a backup for some time.
Is there a best practice for handling account deletions?
CodePudding user response:
I would add one more boolean field to the user account record called for example "IsDeleted". It will be an indicator that the user account has been deleted. Also, adding deleted DateTime could be useful to determine later if you should completely purged that user account record. The best practice is to keep it simple.
CodePudding user response:
This is usually handled via so-called "soft deletes", which mark a record as deleted but don't actually delete it.
This is a common scenario in many frameworks. For example Laravel uses a deleted_at
timestamp property, so you can delete an account, and then run a scheduled task to really delete records that a were deleted more than a certain amount of time ago, say a week. "Undeleting" an account simply requires setting that field to null
.
Soft deletes are useful for the inevitable "but I didn't mean to delete it" scenarios, but also when you perhaps have other tasks that need to be done when you delete a user account, for example removing data from 3rd party services that you have shared the data with, such as mailing list services.
While you may have a legal requirement to delete data under GDPR when requested, it's not absolute and depends on your basis for processing. For example you may be legally obliged to retain records for a certain amount of time, or you may have a contractual requirement to retain records until the account has paid all its bills.
You shouldn't be relying on soft deletes as a defence against password guessing – a strong password policy and 2FA should have a much higher priority against that.