Strength Score
Part of the PowerShell Basics section of Coddy's PowerShell journey. Lesson 24 of 28.
Challenge
EasyTurn the three checks into a score; keep everything you wrote so far.
- The score starts at 0 and gets 1 point for each of: 8 or more characters, at least one digit, at least one capital letter.
- Print
Score:, the score and/3. - With a
switchon the score, printStrength: Strongfor 3,Strength: Mediumfor 2 andStrength: Weakfor anything else.
With the input sunflower42, your script prints:
Password Checker
================
Password: sunflower42
Characters: 11
Length: OK
Digits: 2
Capitals: 0
Score: 2/3
Strength: MediumTry it yourself
# Password Checker
Write-Output "Password Checker"
Write-Output "================"
$pw = Read-Host "Password"
Write-Output "Characters: $($pw.Length)"
if ($pw.Length -ge 8) {
Write-Output "Length: OK"
} else {
Write-Output "Length: too short (need 8)"
}
$digits = 0
$capitals = 0
foreach ($c in $pw.ToCharArray()) {
if ([char]::IsDigit($c)) { $digits++ }
if ([char]::IsUpper($c)) { $capitals++ }
}
Write-Output "Digits: $digits"
Write-Output "Capitals: $capitals"
All lessons in PowerShell Basics
5Project: Password Checker
Project OverviewLength Check