<!---
+++++++++++++++++++++++++++++++
+ GENERATE RANDOM PASSWORD
+++++++++++++++++++++++++++++++
--->
<cffunction name="generatePassword" access="public" returntype="struct" displayname="Generate Password" output="false"
hint="function to generate a random password for a user, plain and encrypted values">
<cfscript>
var passStruct = structNew();
var randNum = 0;
var randChar = 'a';
var passList = '';
var passLength = 8;
var alphaLower = 'a|c|e|g|i|k|m|o|q|s|u|w|y|b|d|f|h|j|l|n|p|r|t|v|x|z';
var alphaUpper = 'A|C|E|G|I|K|M|O|Q|S|U|W|Y|B|D|F|H|J|L|N|P|R|T|V|X|Z';
var numeric = '0|2|4|6|8|9|7|5|3|1';
//create a list of characters
var charlist = alphaLower & '|' & numeric & '|' & alphaUpper;
//create the password
for (i = 1; i lte passLength; i = i + 1)
{
randNum = randRange(1,listlen(charlist,'|')); //random number for the list location
randChar = listGetAt(charList,randNum,'|'); //get character located at randNum position
passList = listAppend(passList,randChar,' '); //list of characters delimited by space
}
//remove all the spaces from the passList variable to set the new password
passStruct.plainPass = reReplace(passList,' ','','all');
//take the new password and encrypt it
passStruct.encryptPass = encryptPassword(passStruct.plainPass);
//return the structure
return passStruct;
</cfscript>
</cffunction>
<!---
+++++++++++++++++++++++++++++++
+ ENCRYPT PASSWORD
+++++++++++++++++++++++++++++++
--->
<cffunction name="encryptPassword" access="public" returntype="string" displayname="Encrypt Password" output="false"
hint="take a password string and encrypt the value using the password key">
<cfargument name="plainPass" type="string" required="true" default="all">
<cfscript>
//DO NOT CHANGE
//this is the random key used to create and read passwords. if you change it all the exisiting passwords will break.
var passwordKey = 'YUndjke395jdiD3j';
encryptPass = trim(encrypt(arguments.plainPass, passwordKey));
return encryptPass;
</cfscript>
</cffunction>