Why define the alphabet? Just use decimal values for the asci char set.
pass = "" ;
for (c=1; c le 7; c=c+1) {
pass = pass & chr(randRange(65,90)) ;
}
pass = pass & randRange(1000,9999) ;
That will do the exact same thing as below much more efficiently, if you
want case sensitive or nums mixed w/ chars it's just a couple extra
rangRanges()s (you can get creative and generate one of each class then
randRange(1,3) to choose which per digit).
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: March 29, 2001 17:10
To: CF-Talk
Subject: Code snippet - random password generator
This script generates a random word 7 letters long plus 4 digits long.
Example code:
<cfset random_word = "">
<cfloop index="ii" from="1" to="7">
<cfset random_number = "#RandRange(1,26)#">
<cfset alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ">
<cfset random_letter = "#Mid(alphabet,random_number,1)#">
<cfset random_word = "#ListAppend(random_word,random_letter)#">
</cfloop>
<cfset random_word = "#Replace(random_word, ",", "", "ALL")#">
<cfset random_number = "#RandRange(1000,9999)#">
<cfset password = "#random_word##random_number#">
<cfoutput>PASSWORD: <b>#password#</b></cfoutput>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at
http://www.fusionauthority.com/bkinfo.cfm
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists