Jump to content

if key exists regenerate a new key ?


PHPFAN10

Recommended Posts

Hi,

 

I have a sign up form that generates a activation key and emails it to user and they cannot login until account has been activated etc.

 

My problem is i am not sure how to in php generate a new activation key if the generated one has already been used.

 

I know how to do the MySQL query to check if activation key already exists but not sure how to basically tell PHP that if the activation key already exists in DB then generate a new key until one is found that does not already exist.

 

I gather i may need a loop but not sure. Could someone please help ?

 

Like i say i know how to do the MySQL query just need some sample code to know how to do what i asked above.

 

Thanks for anyhelp; Much Appreciated

Link to comment
Share on other sites

You would need to query the database table to find out if the newly generated key is already present or not and loop until you generate a key that is not already in the table. You would also probably want to use a counter to limit the number of attempts to a reasonable number in case your code contains an error or you use up all the available key values for the key length you have picked.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.