FastPrepCheck a Password Against a Supplied Policy

Check a Password Against a Supplied Policy

Walmart logoWalmart● EasyFULLTIMEPHONE SCREEN
Learn

Problem statement

Return whether password satisfies the policy supplied by minimumLength, requireLowercase, requireUppercase and requireDigit.

For this exercise, assume the password contains only printable ASCII characters, with codes 32 through 126. Its length must be at least minimumLength. Each enabled class flag also requires at least one matching character: lowercase a through z, uppercase A through Z, or digit 0 through 9. Disabled class flags impose no requirement.

For this exercise, assume other printable characters, including spaces and punctuation, are allowed and count toward length; they satisfy none of those three classes. Return true exactly when every enabled requirement passes. An empty password passes only when the minimum is zero and all class flags are false. Do not modify the input.

Function

checkPassword(password: String, minimumLength: int, requireLowercase: boolean, requireUppercase: boolean, requireDigit: boolean) → boolean

Examples

Example 1

password = "aA0"minimumLength = 3requireLowercase = truerequireUppercase = truerequireDigit = truereturn = true

Authored example: The length is three and the password contains a lowercase letter, an uppercase letter and a digit.

Example 2

password = "hello"minimumLength = 5requireLowercase = truerequireUppercase = truerequireDigit = falsereturn = false

Authored example: The length and lowercase check pass, but the enabled uppercase requirement fails.

Example 3

password = ""minimumLength = 0requireLowercase = falserequireUppercase = falserequireDigit = falsereturn = true

Authored example: An empty string meets the zero minimum and has no enabled class checks.

Constraints

  • For this exercise, assume 0 <= password.length <= 500.
  • For this exercise, assume 0 <= minimumLength <= 500.
  • Every password character is printable ASCII, from code 32 through 126.
  • The three class parameters are Boolean flags.

More Walmart problems

See Walmart hiring insights
public boolean checkPassword(String password, int minimumLength, boolean requireLowercase, boolean requireUppercase, boolean requireDigit) {
    // Write your code here.
    return false;
}
password"aA0"
minimumLength3
requireLowercasetrue
requireUppercasetrue
requireDigittrue
expectedtrue
Checking account…