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
https://forums.phpfreaks.com/topic/261043-whiletrue-ok/
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
https://forums.phpfreaks.com/topic/261043-whiletrue-ok/#findComment-1337839
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.