← PHP / Laravel · Contents

PHP-081 / Advanced

Using only uniqid() to create temporary files

A02:2021 Cryptographic Failures · CWE-340 Generation of Predictable Numbers or Identifiers

Why is this a problem?

uniqid() is time-based and therefore predictable.

How to fix it

php
$downloadKey = bin2hex(random_bytes(16));

Further reading