Validate basic password rules
Check that a password has at least eight characters, contains uppercase, lowercase, and digit characters, and contains no whitespace.
Course progress
Problem 65 of 100
Example → approach → runnable solution
Worked example
See the problem in action
Trace a concrete input through to the verified result.
Example input
password = "Quill2026"
Expected output
True
What is happening?
The password has nine characters, uppercase Q, lowercase letters, digits, and no whitespace, so it satisfies every rule.
Solution strategy
Build the right mental model
Reject short passwords, then scan once while recording which required character categories have appeared.
Core concepts
strings · boolean flags
Complexity
Time O(n), space O(1).
Runnable solution
Learn from working code
Compare languages, copy the code, or open it in the compiler.
Complete C# solution for validate-password-rules
using System;
class Program
{
static bool IsValidPassword(string password)
{
if (password.Length < 8) return false;
bool upper = false, lower = false, digit = false;
foreach (char symbol in password)
{
if (char.IsWhiteSpace(symbol)) return false;
if (char.IsUpper(symbol)) upper = true;
else if (char.IsLower(symbol)) lower = true;
else if (char.IsDigit(symbol)) digit = true;
}
return upper && lower && digit;
}
static void Main()
{
Console.WriteLine(IsValidPassword("Quill2026"));
}
}Knowledge check
Questions students often ask
What is the main idea behind validate basic password rules?
Reject short passwords, then scan once while recording which required character categories have appeared.
What is the time and space complexity of this solution?
Time O(n), space O(1).
Do all language tabs solve the same problem?
Yes. Every program uses the same example and produces the verified output shown on this page. The syntax and a few language-specific data structures differ.