Rich,
Take a look at this. It is perhaps not the best solution, but it is easy
to read / understand. I am opting for using static sets of valid
characters because, while it might be more prone to error over the use
of ascii values (as Tom was suggesting) it gives you a bit more
flexibility in what actually is a valid character (for instance, notice
below that I have added some punctuation into the mix as being valid):
<!--- Set up lower case values. --->
<cfset strLowerCaseAlpha = "abcdefghijklmnopqrstuvwxyz" />
<!--- Set up upper case values. --->
<cfset strUpperCaseAlpha = UCase( strLowerCaseAlpha ) />
<!--- Set up numbers. --->
<cfset strNumbers = "0123456789" />
<!--- Set up additional valid password chars. --->
<cfset strOtherChars = "[EMAIL PROTECTED]&*" />
<!--- Create a set of all valid chars. --->
<cfset strAllValidChars = (
strLowerCaseAlpha &
strUpperCaseAlpha &
strNumbers &
strOtherChars
) />
<!--- Create an array to contain the password. --->
<cfset arrPassword = ArrayNew( 1 ) />
<!--- Create the number. --->
<cfset arrPassword[ 1 ] = Mid(
strNumbers,
RandRange( 1, Len( strNumbers ) ),
1
) />
<!--- Create the lowercase. --->
<cfset arrPassword[ 2 ] = Mid(
strLowerCaseAlpha,
RandRange( 1, Len( strLowerCaseAlpha ) ),
1
) />
<!--- Create the uppercase. --->
<cfset arrPassword[ 3 ] = Mid(
strUpperCaseAlpha,
RandRange( 1, Len( strUpperCaseAlpha ) ),
1
) />
<!--- Create rest of the password. --->
<cfloop
index="intChar"
from="#(ArrayLen( arrPassword ) + 1)#"
to="8"
step="1">
<!--- Pick random value. --->
<cfset arrPassword[ intChar ] = Mid(
strAllValidChars,
RandRange( 1, Len( strAllValidChars ) ),
1
) />
</cfloop>
<!---
Now, SHUFFLE the array. This is perhaps not he
safest thing to do, but on MX for now, it works.
--->
<cfset CreateObject( "java", "java.util.Collections" ).Shuffle(
arrPassword
) />
<cfdump var="#arrPassword#" />
......................
Ben Nadel
Certified Advanced ColdFusion MX7 Developer
www.bennadel.com
Need ColdFusion Help?
www.bennadel.com/ask-ben/
-----Original Message-----
From: Richard White [mailto:[EMAIL PROTECTED]
Sent: Wednesday, January 24, 2007 11:14 AM
To: CF-Talk
Subject: Re: confirming string length, case, and alphanumeric
:) that would actually be really useful thanks ben. i have just been
searching through the internet but would appreciate a specific example.
i was looking for someone that had done a password generator that i
could use but if i could learn the code to do it myself i would be very
grateful
thanks very much ben
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Upgrade to Adobe ColdFusion MX7
Experience Flex 2 & MX7 integration & create powerful cross-platform RIAs
http:http://ad.doubleclick.net/clk;56760587;14748456;a?http://www.adobe.com/products/coldfusion/flex2/?sdid=LVNU
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:267506
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4