cfloop condition loop

Hi Experts:
Is there a cleaner, more better way to do this?  The procedure is to generate a random password and check the newly generated random password for compliance to the password rules.  If it doesn't comply, then a new random password is checked again and so on until a good password is generated.  The checkPassword function returns a return code (rc) with a message if there's a problem with the password.  Usually, if a user is resetting their own password, this message (#rc#) would just be output to the user.  For random password generation, it's not displayed.  Initially, I set rc to TRUE, just so it's not null.  Thank you!
   Here is the code:


<cfset newPW = obj1.getTempPW(#USER_ID#)>
<cfset rc = TRUE>
<cfloop condition="rc neq """"">
   <cfset rc = obj2.checkPassword(form.Email,"#newPW#")>
   <cfif rc neq "">
   <!--- this password is not compliant, generate another --->
      <cfset newPW = obj1.getTempPW(#user_id#)>
   </cfif>
</cfloop>

Open in new window

snix123Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cfMaverickCommented:
you should just be able to check the result in the condition itself.
<cfset newPW = obj1.getTempPW(USER_ID)>
<cfloop condition="#len(obj2.checkPassword(form.Email,newPW))#">
      <cfset newPW = obj1.getTempPW(user_id)>
</cfloop>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gdemariaCommented:
I'm always afraid of infinite loops.  what if your some code changes and the password generator cannot generate a valid password?

This code will bail out after 99 tries..


<cfset newPassword = "">
<cfloop index="xx" from="1" to="99">
   <cfset testPswd = obj1.getTempPW(user_id)>
   <cfif len(obj2.checkPassword(form.Email,testPswd))>
      <cfset newPassword = testPswd>
      <cfbreak> <!--- found a good password, quit ---->
   </cfif>
</cfloop>

<cfif len(newPassword) eq 0>
  Error : unable to generate a new password !
</cfif>

Open in new window

0
snix123Author Commented:
Thanks a bunch!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ColdFusion Language

From novice to tech pro — start learning today.