All challenges
Easy 0 solved 0% acceptance

Password Rules Check

Check a password against simple strength rules.

What you'll learn

  • Check several rules on one string
  • Use flags for digits and letters
  • Return a clear true or false result

Problem

A password is strong if it has at least 8 characters, at least one uppercase letter, at least one lowercase letter and at least one digit (English letters and 0–9).

Implement is_strong_password(password).

Input

password: The password to check (ASCII characters).

Output

Return true if all rules hold, otherwise false.

Constraints

0 ≤ length of password ≤ 100

Examples

Example 1
Input:
password = "Secret123"

Expected output:
expected = True
Input:
std::string password = "Secret123";

Expected output:
bool expected = true;
Input:
string password = "Secret123";

Expected output:
bool expected = true;

Explanation

9 characters with uppercase S, lowercase letters and digits: strong.

Example 2
Input:
password = "password1"

Expected output:
expected = False
Input:
std::string password = "password1";

Expected output:
bool expected = false;
Input:
string password = "password1";

Expected output:
bool expected = false;

Explanation

There is no uppercase letter, so it is not strong.

How to approach it

Try on your own first, then open one hint at a time.

Hint 1

The password must satisfy several independent conditions at once.

Hint 2

Track whether you have seen an uppercase letter, a lowercase letter, and a digit while checking length.

Hint 3

An empty string or short string fails immediately even if it contains mixed characters.

Expected complexity

O(n) time, O(1) extra space

References

This challenge is adapted for CodeUtility. Follow the statement and constraints above.

Learn from others

Community solutions

No published solutions yet. Solve this challenge to share the first one.