InterviewDB Experience

Password Generating: Build a Configurable Secure Password Generator

Interview Experience

Round 1 Coding

Problem

Implement a configurable password generator that produces cryptographically random passwords based on specified rules. Support minimum counts of uppercase, lowercase, digits, and symbols, with a total length constraint.

python
import secrets
import string

class PasswordGenerator:
    def __init__(self, length: int = 16,
                 min_upper: int = 1, min_lower: int = 1,
                 min_digits: int = 1, min_symbols: int = 1,
                 allowed_symbols: str = "!@#$%^&*()"):
        ...
    def generate(self) -> str:
        ...
    def validate(self, password: str) -> bool:
        ...

Example

gen = PasswordGenerator(length=12, min_upper=2, min_lower=2,
                         min_digits=2, min_symbols=2)
pwd = gen.generate()
len(pwd)              -> 12
gen.validate(pwd)     -> True

# Validation rules:
gen.validate("abc")   -> False  # too short, no upper/digit/symbol
gen.validate("Abc1234!@XYZ") -> True

Follow-ups

  1. Why use secrets instead of random for password generation?
  2. How do you ensure the required character counts are met while keeping the rest of the password uniformly random?
  3. How would you add an option to exclude ambiguous characters like 0, O, l, 1, I?
  4. How would you implement a password strength scorer as a separate method?

Full Details

Round 1 Coding

Problem

Implement a configurable password generator that produces cryptographically random passwords based on specified rules. Support minimum counts of uppercase, lowercase, digits, and symbols, with a total length constraint.

python
import secrets
import string

class PasswordGenerator:
    def __init__(self, length: int = 16,
                 min_upper: int = 1, min_lower: int = 1,
                 min_digits: int = 1, min_symbols: int = 1,
                 allowed_symbols: str = "!@#$%^&*()"):
        ...
    def generate(self) -> str:
        ...
    def validate(self, password: str) -> bool:
        ...

Example

gen = PasswordGenerator(length=12, min_upper=2, min_lower=2,
                         min_digits=2, min_symbols=2)
pwd = gen.generate()
len(pwd)              -> 12
gen.validate(pwd)     -> True

# Validation rules:
gen.validate("abc")   -> False  # too short, no upper/digit/symbol
gen.validate("Abc1234!@XYZ") -> True

Follow-ups

  1. Why use secrets instead of random for password generation?
  2. How do you ensure the required character counts are met while keeping the rest of the password uniformly random?
  3. How would you add an option to exclude ambiguous characters like 0, O, l, 1, I?
  4. How would you implement a password strength scorer as a separate method?

About This Question

This is a candidate experience report from a patreon interview during the onsite round.

It covers the following topics: Coding, Strings, Onsite .