Found this PS script to check Password Complexity.
Very short but works nicely.
Would like to duplicate in WB but cannot find correct functions to use.
...Or maybe call from WB?
here is the code, thanks!
$Input = Read-Host "Please enter your password. `nPassword must meet complexity requirements:
`nAt least one upper case English letter [A-Z]`nAt least one lower case English letter [a-z]`nAt least one digit [0-9]`nAt least one special character (!,@,#,%,^,&,$)`nMinimum 7 in length."
if(($input -cmatch '[a-z]') -and ($input -cmatch '[A-Z]') -and ($input -match '\d') -and ($input.length -ge 7) -and ($input -match '!|@|#|%|^|&|$'))
{
Write-Output "$input is valid password"
}
else
{
Write-Output "$input is Invalid password"
}
You can use one or more WinBatch string functions to duplicate the PS business or call the .Net regular expression class by using the WinBatch CLR hosting subsystem. And yes, you could call a PS script using CLR hosting if you think you must but there are more direct approaches. .Net regex examples can be found in the Tech Database and the WinBatch string functions are all documented in the Consolidated WIL help file and on-line. The links to the Tech Database and the online version of help are in the menu bar at the top of this forum.
No doubt that there are better approaches but here is one example off-the-top:
pwd ="@Topsecret1"
Uletters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Digits = "012456789"
Lletters = StrLower(Uletters)
Special = "!@#%%^&$"
if StrLen(pwd) > 6&&StrScan(pwd,Uletters,1,@Fwdscan)&&StrScan(pwd,Digits,1,@Fwdscan)&&StrScan(pwd,Lletters,1,@Fwdscan)&&StrScan(pwd,Special,1,@Fwdscan)
Text = "Password OK"
else
Text = "Password invalid"
endif
Message("Password Check", Text)
exit
This simple CLR code seems to generate passwords that meet the criteria
;simple password generator with CLR
;length and nonchars can vary
length = 15
nonchars = 4
ObjectClrOption("useany", "System.Web")
oSecure = ObjectClrNew("System.Web.Security.Membership")
password = oSecure.GeneratePassword(length,nonchars)
Message("Password Created",password)
Exit
Your sample works great, thanks much!