phanalist

E0056: Weak Randomness for Security-Sensitive Value

In plain English: Functions such as rand(), mt_rand(), and uniqid() are predictable. They are fine for games and samples, but not for tokens, passwords, salts, nonces, or other secrets.

Why it matters: If an attacker can predict a token, they may be able to guess password-reset links, CSRF tokens, session identifiers, or API keys.

Bad

$token = uniqid();
$password = password_hash(mt_rand(), PASSWORD_DEFAULT);
$nonce = (string) rand();

Good

$token = bin2hex(random_bytes(32));
$code = random_int(100000, 999999);
$passwordHash = password_hash($password, PASSWORD_DEFAULT);

random_bytes() is for tokens and salts. random_int() is for numeric codes. password_hash() handles password salts for you.

What the rule checks

When it does not report

How to fix

Model limits

Configuration

E0056 has no configuration options and is enabled by default.