?
Solved

cfloop condition loop

Posted on 2010-04-06
3
Medium Priority
?
489 Views
Last Modified: 2012-05-09
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

0
Comment
Question by:snix123
3 Comments
 
LVL 4

Accepted Solution

by:
cfMaverick earned 1000 total points
ID: 29934881
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
 
LVL 39

Assisted Solution

by:gdemaria
gdemaria earned 1000 total points
ID: 29935929
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
 

Author Closing Comment

by:snix123
ID: 31711476
Thanks a bunch!
0

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Get the source code for a fully functional Access application shell with several popular security features that Access VBA application developers desire, but find difficult or impossible to figure out how to code. You get the source code for managi…

594 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question