Hey devs,
You write secure code. You hash passwords. You follow best practices.
But sometimes... that’s not enough.
Password leaks are real, dangerous, and can affect you — whether you're a solo indie hacker, a startup dev, or an engineer at a FAANG company.
This post is your one-stop, dev-friendly guide to:
- Understand what password leaks are
- How they happen
- How they affect you and your users
- Tools to detect leaks
- How to use Python to check for compromised credentials
- Preventive steps every developer should take
Let’s dive in 👇
🤯 What Exactly Is a Password Leak?
A password leak happens when login credentials — often from a database breach — are exposed to the public or sold on dark web markets.
A leak might contain:
- Email + password combinations
- Hashes (like MD5, SHA-1 — or bcrypt if you're lucky)
- Tokens, security questions, or even session IDs
💥 Real-World Breaches That Shook the Dev World
Some infamous ones:
Service | Year | Records Leaked |
---|---|---|
2012 | 164M+ accounts | |
Dropbox | 2012 | 68M credentials |
Adobe | 2013 | 150M+ credentials |
Canva | 2019 | 137M+ accounts |
Twitter/X | 2023 | 200M+ scraped emails |
Info:
🔗 Have I Been Pwned - Breach Database
🔗 Firefox Monitor
🧠 Why Should You, a Developer, Care?
- You might accidentally commit secrets (like API keys) to a Git repo.
- Your users may reuse the same passwords across sites.
- If your site is breached, even with hashed passwords, you're liable.
- You may work on integrations that use 3rd-party APIs — and one of them gets breached.
🕵️♂️ How to Detect Password Leaks (with Python)
Let’s build a simple Python script to check if a password has been leaked using the HaveIBeenPwned API — which is free and supports k-Anonymity.
📖 Official docs: https://haveibeenpwned.com/API/v3#PwnedPasswords
Step 1: Install Dependencies
pip install requests hashlib
Step 2: Hash the Password Using SHA-1
HIBP requires you to send the first 5 characters of a SHA-1 hash to preserve privacy.
import hashlib
def hash_password_sha1(password):
sha1 = hashlib.sha1(password.encode('utf-8')).hexdigest().upper()
prefix = sha1[:5]
suffix = sha1[5:]
return prefix, suffix
Step 3: Query HIBP's API
import requests
def get_leaked_suffixes(prefix):
url = f"https://api.pwnedpasswords.com/range/{prefix}"
response = requests.get(url)
return response.text.splitlines()
Step 4: Check if the Password is Leaked
def is_password_leaked(password):
prefix, suffix = hash_password_sha1(password)
leaked_hashes = get_leaked_suffixes(prefix)
for line in leaked_hashes:
leaked_suffix, count = line.split(":")
if leaked_suffix == suffix:
return True, int(count)
return False, 0
Step 5: Test It
password = input("Enter a password to check: ")
leaked, count = is_password_leaked(password)
if leaked:
print(f"⚠️ Password has been leaked {count} times!")
else:
print("✅ Your password was not found in known leaks.")
🧪 Bonus: Check Entire Credential Files for Leaks
Imagine you're auditing an old system or app, and you have a list of user passwords (hopefully hashed). You can build a script to bulk-check them against breach databases.
Here’s a GitHub repo by security researcher Mike Pound that can be integrated or extended for enterprise use.
🧰 Dev Tools to Detect & Prevent Password Leaks
Tool | What it does | Link |
---|---|---|
GitLeaks | Scan repos for secrets | gitleaks.io |
TruffleHog | Scans Git history for keys | trufflesecurity.com |
Punk Security - Scan Secrets | GitHub action for leaks | PunkSecurity/scan |
HaveIBeenPwned API | Query leaked passwords | API Docs |
🛡️ Best Practices to Prevent Password Leaks
As a developer, here are steps you can take today:
- Never store plaintext passwords.
- Use
bcrypt
orargon2
with salt. - Avoid MD5/SHA-1 — they’re easily brute-forced.
- Audit your Git repositories.
- Use GitSecrets or GitHub’s secret scanning.
- Enforce strong password policies.
- Length > complexity
- Suggest passphrases (like:
correct-horse-battery-staple
)
- Check user credentials on registration.
- Use the HIBP API to block reused/compromised passwords.
- Use 2FA/MFA.
- Even if credentials leak, the second factor saves you.
- Educate users.
📚 Further Reading & Learning
- 🔐 OWASP Top 10: Broken Authentication
- 📊 List of Known Breaches
- 🧑💻 Troy Hunt’s Blog on Password Security
🎁 Bonus: Build Your Own Breach Alert CLI Tool
Want to go further?
Try building a CLI tool using click
or argparse
that:
- Accepts email or password inputs
- Checks HIBP for leaks
- Stores results in a local log
- Optionally sends you email alerts (using
smtplib
)
💬 Wrapping Up
A password leak isn’t just a security issue — it's a trust issue.
By being proactive, you protect:
- Your apps
- Your users
- And your own digital footprint
💡 Start by adding a simple password leak check to your login or registration flows.
You'll sleep better at night knowing you're one step ahead.
👋 If you liked this guide, consider checking out my other posts on Python Developer Resources - Made by 0x3d.site for curated lists, tools, and code snippets for modern developers.
Also Try Downloading Out 6,600+ AI SEO Optimized Artiles on Stackoverflow Questions with -> here
6,600+ Technical StackOverFlow Q and A Dev. Articles — Blog-Ready and SEO-Powered
Top comments (0)