Digits And Capitals
Part of the PowerShell Basics section of Coddy's PowerShell journey. Lesson 23 of 28.
Challenge
EasyStrong passwords mix in digits and capital letters. Count both; keep everything you wrote so far.
$pw.ToCharArray()gives the characters of the password as an array. Loop over it withforeach.[char]::IsDigit($c)isTruefor a digit and[char]::IsUpper($c)for a capital letter. Count each kind.- After the length line, print
Digits:and the number of digits, thenCapitals:and the number of capital letters.
With the input Sunflower42, your script prints:
Password Checker
================
Password: Sunflower42
Characters: 11
Length: OK
Digits: 2
Capitals: 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)"
}
All lessons in PowerShell Basics
5Project: Password Checker
Project OverviewLength Check