Menu
CoddyTech

Check Many Passwords

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

challenge icon

Challenge

Easy

Check many passwords in one run; keep the title and every check you wrote.

  1. Print the title and the border once, at the start.
  2. In a while ($true) loop, read a password with the prompt Password. An empty line ends the loop: -not $pw is True for an empty string, and also when there is no input left (Read-Host then returns $null).
  3. For every other password, print the same lines as before: characters, length, digits, capitals, score and strength.
  4. After the loop, print Checked: and how many passwords were checked, then Strong: and how many of them were strong.

With the input Sunflower42, cat and an empty line, your script prints:

Password Checker
================
Password: Sunflower42
Characters: 11
Length: OK
Digits: 2
Capitals: 1
Score: 3/3
Strength: Strong
Password: cat
Characters: 3
Length: too short (need 8)
Digits: 0
Capitals: 0
Score: 0/3
Strength: Weak
Password:
Checked: 2
Strong: 1

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"
$score = 0
if ($pw.Length -ge 8) { $score++ }
if ($digits -gt 0) { $score++ }
if ($capitals -gt 0) { $score++ }
Write-Output "Score: $score/3"
switch ($score) {
    3 { Write-Output "Strength: Strong" }
    2 { Write-Output "Strength: Medium" }
    default { Write-Output "Strength: Weak" }
}

All lessons in PowerShell Basics