> Does any one of you CF experts out there (as I am a real newbie)
> know how to create a random password string, for 8 characters?
> 
> Is there a tag out there to use? Is there a simple, known, CFRANDOM
> function or something? I would imagine this has been done before.

I threw this together. It's not spectacular; it's just a simple custom tag
which uses ASCII codes for 0-9, a-z and A-Z. You'd call it like this:

<!--- example.cfm --->
<cf_password maxlength="8" returnval="newpwd">
<cfoutput>#newpwd#</cfoutput>
<!--- end example.cfm --->

It increases the likelihood of the use of numbers in a password; rather than
10 in 62, the likelihood is artificially increased to 1 in 3. I was too lazy
to do it right.

<!--- password.cfm --->
<cfparam name="Attributes.MinLength" default="8">
<cfparam name="Attributes.MaxLength" default="14">
<cfparam name="Attributes.ReturnVal" default="password">

<cfset intPwdLength = RandRange(Attributes.MinLength, Attributes.MaxLength)>
<cfset strPwd = "">

<cfloop index="i" from="1" to="#intPwdLength#">
        <cfset WhichRange = RandRange(1, 3)>
        <cfif WhichRange is 1>
                <cfset Start = 48>
                <cfset End = 57>
        <cfelseif WhichRange is 2>
                <cfset Start = 65>
                <cfset End = 90>
        <cfelse>
                <cfset Start = 97>
                <cfset End = 122>
        </cfif>
        <cfset strPwd = strPwd & Chr(RandRange(Start, End))>
</cfloop>

<cfset rs = SetVariable("Caller." & Attributes.ReturnVal, strPwd)>
<!--- end password.cfm --->

Enjoy!

Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/
voice: (202) 797-5496
fax: (202) 797-5444

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to