Start learning free

LESSON 197 OF 678 · PROJECTS: EVERYDAY PROGRAMS

Password Strength V1 - Length Check

Practice

A tiny password strength checker that looks only at the length of the password.

You start with:

let password = "Secret99"

Build:

Password length: 8
OK

Rules:

  • Print "Password length: " followed by the number of characters.
  • If the length is at least 8, print OK; otherwise print Too short.

Try other passwords: with abc the output is

Password length: 3
Too short

Swift's String.count property gives you the number of characters.

let password = "Secret99"

let length = password.count
print("Password length: \(length)")
if length >= 8 {
    print("OK")
} else {
    print("Too short")
}

STEP 1 OF 4
    Ctrl + Enter to check