Jump to content

while(TRUE) - OK?


Gibbs

Recommended Posts

Apart from the fact this can cause an infinite loop is it OK to use?

 

$user->reset_token = $user->generate_password(32);

// Make sure the token is unique
while(TRUE)
{
$count = ORM::factory('manager')->where('reset_token', '=', $user->reset_token)->count_all();
if($count < 1) break;			

$user->reset_token = $user->generate_password(32);
}

 

Or would you approach the logic for this differently?

 

Thoughts appreciated. Cheers

Link to comment
Share on other sites

what are you actualy doing?

 

The idea is that it keeps generating passwords (or in this case tokens) until it finds a unique one.

 


do {
   $user->reset_token = $user->generate_password(32);.
   $count = ORM::factory('manager')->where('reset_token', '=', $user->reset_token)->count_all();
} while ($count < 1);

 

That is what I would do.

 

Excellent. That makes a lot more sense!

 

Thanks.

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.