Menu
CoddyTech

Strength Score

Part of the PowerShell Basics section of Coddy's PowerShell journey. Lesson 24 of 28.

challenge icon

Challenge

Easy

Turn the three checks into a score; keep everything you wrote so far.

  1. 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.
  2. Print Score: , the score and /3.
  3. With a switch on the score, print Strength: Strong for 3, Strength: Medium for 2 and Strength: Weak for 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: Medium

Try 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