Check Many Passwords
Part of the PowerShell Basics section of Coddy's PowerShell journey. Lesson 25 of 28.
Challenge
EasyCheck many passwords in one run; keep the title and every check you wrote.
- Print the title and the border once, at the start.
- In a
while ($true)loop, read a password with the promptPassword. An empty line ends the loop:-not $pwisTruefor an empty string, and also when there is no input left (Read-Hostthen returns$null). - For every other password, print the same lines as before: characters, length, digits, capitals, score and strength.
- After the loop, print
Checked:and how many passwords were checked, thenStrong: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: 1Try 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
5Project: Password Checker
Project OverviewLength Check