Gibbs Posted April 16, 2012 Share Posted April 16, 2012 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 More sharing options...
Muddy_Funster Posted April 16, 2012 Share Posted April 16, 2012 what are you actualy doing? Link to comment https://forums.phpfreaks.com/topic/261043-whiletrue-ok/#findComment-1337833 Share on other sites More sharing options...
kicken Posted April 16, 2012 Share Posted April 16, 2012 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. Link to comment https://forums.phpfreaks.com/topic/261043-whiletrue-ok/#findComment-1337834 Share on other sites More sharing options...
Gibbs Posted April 16, 2012 Author Share Posted April 16, 2012 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.