I am writing up a user registration application in PHP as part of my learning process. I have written up the general rules my code should follow. Please let me know what you guys think of it.
Have a form with the email address and password.
Generate 2 random tokens to be appended to the URL to validate the email and complete the registration. Send user en email with the URLs. Use the first token to continue the registration and the second token to cancel (In the case where the registration request was unsolicited).
At this point, in the database table, I maintain a table with 6 columns - email, password, register_token, cancel_register_token, counter, timer.
When user clicks on the link to continue with the registration process, prompt the user for the password. If the user had inadvertently entered an incorrect email address, then that someone else obviously doesn't know the password and cant continue with the registration.
If the user who already has an active email in the db, waiting to register, wants an activation email sent again (maybe someone else registered the email on his behalf, unsolicited and he doesn't have the password to continue), then create another 2 random tokens, erasing the first set from the table and keeping a counter, increasing the counter each time a new set of tokens are generated against an email. When the counter reaches a maximum, do not accept any more requests. Maybe a max of 5 such requests and no more.
Keep the register link alive for 1 day if there is no activity. Use the timer column for the same.