Edoooo
Edoooo

Reputation: 19

activation code in email how to make

i need to make activation code for my users. When users are registered, my php script would send an email to users and i dont know how to implement activation code or activation link. I dont know logic for this

Upvotes: 1

Views: 8557

Answers (5)

Arno
Arno

Reputation: 1253

You can also use a table-less solution to generate one-time passwords. Have a look at http://bakery.cakephp.org/articles/ashevat/2010/03/12/how-to-implament-one-time-password-for-forgot-my-password-and-account-activation-processes

Upvotes: 0

mmhan
mmhan

Reputation: 731

Or you could simply use CakeDC's users plugin and avoid all that trouble.

Upvotes: 0

Majid Fouladpour
Majid Fouladpour

Reputation: 30252

  1. upon registration create a random string $user_rand;
  2. store the random string in the users table in activation_secret column, set the active column to 0
  3. hash the random string and send an email to the email address the user provided and include a link to your activation page, include the hash as a parameter. e.g. http://host.com/activate.php?activation_code=sfer3423ste&username=john
  4. in activatate.php extract the username and the activation code (which is the hash you sent)
  5. query users table for a record which has active=0 and user=john, return the value in activation_secrete
  6. hash activation_secrete and compare the hash with activation code from the url, if they match, the user should be validated (set active column to 1) if not, inform the user the activation code is not recognized.

You can build on this and make it robust and add exception handling. E.g. you can also set a life time for the activation secrete and more.

Upvotes: 8

Sam Holder
Sam Holder

Reputation: 32946

I've not done it but I would have thought that it would be along the lines of:

  • When a user registers generate an activation code, and store it associated with the users id
  • Have a page which validates a code. this will look up the code given in the url (or have the user enter it manually in a field on the page) and see if it is the code associated with the user (must be logged in to see this page)
  • Generate a url which goes to the above page and provides the code in the url.
  • insert the url in an email and send to the user

Upvotes: 1

George Cummins
George Cummins

Reputation: 28926

This is a four-step process:

  1. Create the activation code
  2. Store it in a database
  3. Email the code to the user with a link to your verification script
  4. Check the code the user enters in your verification script against the value stored in the database.

For an example implementation, please see:

http://www.learnphponline.com/scripts/email-activation-for-php-forms

Upvotes: 11

Related Questions