Detection
Predictable Reset Tokens
Detection
A password-reset token needs to be cryptographically unguessable, because possession of the token effectively grants temporary authority to reset the account's password.
A vulnerable implementation may derive the token from predictable information:
// Weak β derived from predictable values
$token = md5($user->email . time());// Correct β independently generated cryptographic randomness
$token = bin2hex(random_bytes(32));The problem with the first implementation isn't simply that it uses MD5. The fundamental problem is that the token is derived from values an attacker may know or be able to predict.
If an attacker knows the victim's email address and can narrow down when the reset token was generated, they may be able to reproduce candidate tokens without ever intercepting the original reset message.
The same problem can occur with other predictable inputs:
username + timestamp
email + timestamp
user ID + timestamp
incrementing database ID
static secret + user-controlled value
Hashing these values does not make them unpredictable. A cryptographic hash is deterministic: if the attacker can reconstruct the same input, they can calculate the same output.
A secure implementation instead generates the token independently using a cryptographically secure random number generator:
$token = bin2hex(random_bytes(32));The server should then associate the token with the appropriate account and enforce a limited expiration period and single-use behavior.
The distinction is:
Hashing predictable data β predictable output
Cryptographically random generation β unpredictable token