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).
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.
Similar Modules
TOTP Two-Factor Auth
Generate and verify time-based one-time passwords (TOTP) compatible with Google Authenticator.
python
·
Advanced
Express CSRF Protection with Double Submit
Implement double-submit CSRF protection in Express without server-side session storage.
javascript
·
Intermediate
ClamAV Malware Scanner Cron
Run ClamAV on upload directory and quarantine infected files automatically.
bash
·
Advanced