REGEXVAULTv2.0
Security/Password Formats
Verified Safe

MD5 Hash (Deprecated — Detection Only) Regex for PHP

/^[a-f0-9]{32}$/i

What this pattern does

This page provides a lightweight, single-purpose regular expression for matching md5 hash (deprecated — detection only), ported and verified for PHP. In security-sensitive code, using an unverified regex can open the door to both false positives and denial-of-service attacks. The snippet below is ready to drop into your PHP project — whether you're validating in a Laravel validator, a WordPress plugin, or a standalone PHP script.

Php Implementation

Php
<?php
// MD5 Hash (Deprecated — Detection Only)
// ReDoS-safe | RegexVault — Security > Password Formats

define('MD5_HASH_DEPRECATED_DETECTION_ONLY_PATTERN', '/^[a-f0-9]{32}$/');

function validate_md5_hash_deprecated_detection_only(string $input): bool {
    return (bool) preg_match(MD5_HASH_DEPRECATED_DETECTION_ONLY_PATTERN, $input);
}

// Example
var_dump(validate_md5_hash_deprecated_detection_only("d41d8cd98f00b204e9800998ecf8427e")); // bool(true)

Test Cases

Matches (Valid)
Rejects (Invalid)
d41d8cd98f00b204e9800998ecf8427ed41d8cd98f00b204e9800998ecf8427
098f6bcd4621d373cade4e832627b4f6d41d8cd98f00b204e9800998ecf8427eX
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ

When to use this pattern

This pattern is drawn from the Security > Password Formats category and carries a ReDoS-safe certification. That matters for PHP developers because especially relevant in PHP where PCRE backtracking limits can trigger silent failures on malicious input. RegexVault audits patterns against known backtracking attack vectors, ensuring you have the necessary context before using this regex in a high-stakes production environment.

Common Pitfalls

MD5 hashes of passwords can be cracked in milliseconds with GPU rainbow tables for passwords under 10 characters. A database of MD5-hashed passwords is effectively a plaintext database for short passwords.

Technical Notes

MD5 is cryptographically broken — collision attacks are trivial, preimage attacks are feasible. Never use MD5 for password hashing or security purposes. Use only for checksums where collision resistance is not required (e.g., non-security file deduplication). Include this pattern only for detection/migration purposes.

Have a pattern that belongs in the vault?

Submit it for review — community-verified patterns get credited to your GitHub handle. Free submissions join the queue. Priority review available for $15.

Submit a Pattern