CFLib.org – Common Function Library Project

MakePassword()

Last updated December 18, 2001

author

Alan McCollough

Version: 1 | Requires: CF5 | Library: SecurityLib

Description:
Generates a random 8-character password that is free of annoying easily confused characters such as 1 or l, O or 0. This is done by taking a UUID, combining parts of it into two-byte chunks, and treating the two-byte chunk as a hexadecimal number. This number is then converted into base-10 and converted into a chr(). This is done until 8 such chars are generated. The result is compared to see if any unwanted similar chars exist, and if so, the sequence is re-ran. This is done by taking a UUID, combining parts of it into two-byte chunks, and treating the two-byte chunk as a hexadecimal number. This number is then converted into base-10 and converted into a chr(). This is done until 8 such chars are generated. The result is compared to see if any unwanted similar chars exist, and if so, the sequence is re-ran.

Return Values:
Returns a string.

Example:

<CFOUTPUT>
Here is a random password: #MakePassword()#
</CFOUTPUT>

Parameters:

No arguments.

Full UDF Source:

/**
 * Generates an 8-character random password free of annoying similar-looking characters such as 1 or l.
 * 
 * @return Returns a string. 
 * @author Alan McCollough (amccollough@anmc.org) 
 * @version 1, December 18, 2001 
 */
function MakePassword()
{      
  var valid_password = 0;
  var loopindex = 0;
  var this_char = "";
  var seed = "";
  var new_password = "";
  var new_password_seed = "";
  while (valid_password eq 0){
    new_password = "";
    new_password_seed = CreateUUID();
    for(loopindex=20; loopindex LT 35; loopindex = loopindex + 2){
      this_char = inputbasen(mid(new_password_seed, loopindex,2),16);
      seed = int(inputbasen(mid(new_password_seed,loopindex/2-9,1),16) mod 3)+1;
      switch(seed){
        case "1": {
          new_password = new_password & chr(int((this_char mod 9) + 48));
          break;
        }
	case "2": {
          new_password = new_password & chr(int((this_char mod 26) + 65));
          break;
        }
        case "3": {
          new_password = new_password & chr(int((this_char mod 26) + 97));
          break;
        }
      } //end switch
    }
    valid_password = iif(refind("(O|o|0|i|l|1|I|5|S)",new_password) gt 0,0,1);	
  }
  return new_password;
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson