So as a continuation of my last question This one. i got this code as a anwser but now i wold like how i could exclude some requirements
function Test-AdminPassword {
[CmdletBinding()]
Param(
[Parameter(Position = 0, Mandatory=$true)]
[string]$Password,
[Parameter(Position = 1)]
[int]$Requirements = 5
)
$result = 0
# test length between 12 and 24
if ($Password.Length -in 12..24) {
$result++
}
# test uppercase
if (($Password -creplace '[^A-Z]', '').Length -ge 3) {
$result++
}
# test lowercase
if (($Password -creplace '[^a-z]', '').Length -ge 3) {
$result++
}
# test digits
if (($Password -replace '[^0-9]', '').Length -ge 3) {
$result++
}
# test special characters
if (($Password -creplace '[^!@$#%^&*()_+\-=\[\]{};'':"\\|,.<>\/? ]', '').Length -ge 3) {
$result++
}
# return $true if the password complies with at least $requirements
return ($result -ge $Requirements)
}
the question i have now is how can i edit this so i can exclude special characters because in a Admin Username you can use only lowercase characters
Here's a complete re-write of my earlier function. This one uses a lot more parameters for you to play with, but then it can be used for testing both an admin username and also to test an inputted password.
For testing Passwords use it like this:
For testing User names use it like this: