Security python Advanced

Password Strength Validator

Validate password strength: length, complexity, and breach check via HaveIBeenPwned API.

python
import hashlib, httpx, re

def check_password(pwd: str) -> dict:
    issues = []
    if len(pwd) < 12:       issues.append("Too short (min 12 chars)")
    if not re.search(r"[A-Z]", pwd): issues.append("Missing uppercase letter")
    if not re.search(r"\d",   pwd):  issues.append("Missing digit")
    if not re.search(r"[!@#$%^&*]", pwd): issues.append("Missing special char")
    sha1 = hashlib.sha1(pwd.encode()).hexdigest().upper()
    r = httpx.get(f"https://api.pwnedpasswords.com/range/{sha1[:5]}")
    if sha1[5:] in r.text:   issues.append("Password found in breach database!")
    return {"ok": not issues, "issues": issues}

Prerequisites

  • httpx
  • python >= 3.10

Pro Tips

  • → Never send the full hash — only the first 5 chars (k-anonymity).

Was this module useful?

Share your experience — it helps the team improve.

Leave Feedback

Commercial Licensing

Acquire a production access token or template license for enterprise deployment.

Module Info

Language
python
Level
Advanced
Read time
4 min
Published
Dec 2025
License
Commercial License

Newsletter

New modules every week, directly to your inbox.