Menu
Coddy logo textTech

Recap - Validation Function

Part of the Fundamentals section of Coddy's Swift journey — lesson 56 of 86.

challenge icon

Challenge

Easy
Write a function isValidPassword that takes password and minLength and returns whether the password meets the validation criteria.

A password is valid if it satisfies all of the following conditions:

Conditions:

  • The password length must be at least minLength characters
  • The password length must not exceed 20 characters
  • The password must not be equal to "password" (case-sensitive)

Parameters:

  • password (String): The password to validate
  • minLength (Int): The minimum required length

Returns: true if all conditions are met, false otherwise (Bool)

For example, if password is "Swift123" and minLength is 6, the function returns true because the password is 8 characters (at least 6), not more than 20, and not equal to "password".

Try it yourself

func isValidPassword(password: String, minLength: Int) -> Bool {
    // Write code here
}

All lessons in Fundamentals