Tuesday, July 29, 2008

Coldfusion Randomizing Password

I had a problem when I needed to distribute an user name and password to each user registered in my application that written in Coldfusion. For security purpose, I needed to those password randomized before I send it. so, I was googling and found the interesting one. here you go.

 <cfset strLowerCaseAlpha = "abcdefghijklmnopqrstuvwxyz" />  
<cfset strUpperCaseAlpha = UCase( strLowerCaseAlpha ) />
<cfset strNumbers = "0123456789" />
<cfset strOtherChars = "~!@##$%^&*" />
<cfset strAllValidChars = (strLowerCaseAlpha &strUpperCaseAlpha &strNumbers ) />
<cfset arrPassword = ArrayNew( 1 ) />
<cfset arrPassword[ 1 ] = Mid(strNumbers,RandRange( 1, Len( strNumbers ) ),1) />
<cfset arrPassword[ 2 ] = Mid(strLowerCaseAlpha,RandRange( 1, Len( strLowerCaseAlpha ) ),1) />
<cfset arrPassword[ 3 ] = Mid(strUpperCaseAlpha,RandRange( 1, Len( strUpperCaseAlpha ) ),1) />
<cfloop index="intChar" from="#(ArrayLen( arrPassword ) + 1)#" to="8" step="1">
<cfset arrPassword[ intChar ] = Mid(strAllValidChars,RandRange( 1, Len( strAllValidChars ) ),1) />
</cfloop>
<cfset CreateObject( "java", "java.util.Collections" ).Shuffle(arrPassword) />
<cfset strPassword = ArrayToList(arrPassword,"") />

Saturday, July 26, 2008

Greetings

Hi everyone,

I start to take off from something sounds : "Let Share". for the comment, I highly appreciate.