CFLib.org – Common Function Library Project

pwStrength(pwString)

Last updated October 14, 2008

author

charlie griefer

Version: 1 | Requires: CF5 | Library: StrLib

Description:
Returns a structure that holds data used to check the strength of a user supplied password. keys include: string length number of alpha characters number of uppercase alpha characters number of lowercase alpha characters number of numeric characters number of bad (non alpha-numeric characters)

Return Values:
Returns a struct.

Example:

<cfset myStr = "dfWE2d %@ df4" />
<cfdump var="#pwStrength(myStr)#" />

Parameters:

Name Description Required
pwString String to check. Yes

Full UDF Source:

/**
 * Checks the strength of a user supplied password.
 * 
 * @param pwString      String to check. (Required)
 * @return Returns a struct. 
 * @author charlie griefer (charlie@griefer.com) 
 * @version 1, October 14, 2008 
 */
function pwStrength(pwString) {
    var retStruct = structNew();

    retStruct.originalString    = arguments.pwString;
    retStruct.originalLength    = len(arguments.pwString);
    retStruct.numericVals        = len(rereplace(pwString, '[^0-9]', '', 'all'));
    retStruct.alphas            = len(rereplaceNoCase(pwString, '[^a-z]', '', 'all'));
    retStruct.alphaUppers        = len(rereplace(pwString, '[^A-Z]', '', 'all'));
    retStruct.alphaLowers        = len(rereplace(pwString, '[^a-z]', '', 'all'));
    retStruct.badChars            = len(rereplace(pwString, '[\w]', '', 'all'));
    
    return retStruct;
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson