skills/weak-password-hashing-anti-pattern/SKILL.md
Security anti-pattern for weak password hashing (CWE-327, CWE-759). Use when generating or reviewing code that stores or verifies user passwords. Detects use of MD5, SHA1, SHA256 without salt, or missing password hashing entirely. Recommends bcrypt, Argon2, or scrypt.
npx skillsauth add igbuend/grimbard weak-password-hashing-anti-patternInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Severity: High
Applications use fast general-purpose hash functions (MD5, SHA-1, SHA-256) without salting for password storage, enabling rapid cracking via rainbow tables or GPU-accelerated brute-force (billions of hashes per second). Results in mass account compromise and credential stuffing attacks.
The anti-pattern is using cryptographic hash functions that are too fast or lack essential features like salting and adjustable work factors, making them vulnerable to offline attacks.
# VULNERABLE: Using MD5 for password hashing.
import hashlib
def hash_password_md5(password):
# MD5 is a cryptographically broken hash function.
# It is extremely fast, and rainbow tables for MD5 are widely available.
return hashlib.md5(password.encode()).hexdigest()
def verify_password_md5(password, stored_hash):
return hash_password_md5(password) == stored_hash
# Another example: plain SHA-256 without salting.
def hash_password_sha256_unsalted(password):
# SHA-256 is a strong hash for data integrity, but too fast for passwords.
# Without a salt, identical passwords result in identical hashes.
return hashlib.sha256(password.encode()).hexdigest()
# Problems:
# - Speed: MD5/SHA-256 can compute billions of hashes per second.
# - No Salt: Allows rainbow table attacks and reveals users with identical passwords.
# - No Work Factor: Cannot be slowed down to resist brute-force attacks.
# SECURE: Use a password-hashing algorithm designed to be slow and include a unique salt.
import bcrypt # Or Argon2, scrypt
def hash_password_secure(password):
# bcrypt generates unique salt per password and supports adjustable work factor.
# Higher rounds = slower hashing = better brute-force resistance.
hashed_password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt(rounds=12))
return hashed_password.decode('utf-8') # Store the hashed password as a string.
def verify_password_secure(password, stored_hash):
# checkpw() verifies password against stored hash with constant-time comparison.
# Extracts salt and work factor from stored hash to prevent timing attacks.
return bcrypt.checkpw(password.encode('utf-8'), stored_hash.encode('utf-8'))
# Recommended algorithms (in order of current preference):
# 1. Argon2id (best practice for new applications)
# 2. bcrypt
# 3. scrypt
# Always use libraries for password hashing; never implement your own.
hashlib.md5(), hashlib.sha1(), or hashlib.sha256() being used for passwords.bcrypt, argon2, or scrypt libraries are used.password or password_hash column in your user database.
$2a$ (bcrypt), $argon2id$ (Argon2), or $s2$ (scrypt)?development
Security anti-pattern for Cross-Site Scripting vulnerabilities (CWE-79). Use when generating or reviewing code that renders HTML, handles user input in web pages, uses innerHTML/document.write, or builds dynamic web content. Covers Reflected, Stored, and DOM-based XSS. AI code has 86% XSS failure rate.
development
Security anti-pattern for XPath injection vulnerabilities (CWE-643). Use when generating or reviewing code that queries XML documents, constructs XPath expressions, or handles user input in XML operations. Detects unescaped quotes and special characters in XPath queries.
development
Security anti-pattern for weak encryption (CWE-326, CWE-327). Use when generating or reviewing code that encrypts data, handles encryption keys, or uses cryptographic modes. Detects DES, ECB mode, static IVs, and custom crypto implementations.
development
Security pattern for self-contained token authentication (e.g., JWT). Use when implementing stateless authentication, designing tokens with embedded claims, or building systems where tokens contain principal information and can be verified without server-side storage. Specialization of Authentication pattern.