← PHP / Laravel · Contents

PHP-064 / Beginner

PHP loose comparison (==) and type juggling

A07:2021 Identification and Authentication Failures · CWE-697 Incorrect Comparison

Why is this a problem?

Comparisons can be bypassed; for example, "0e123" == "0e456" evaluates to true in PHP 7 and earlier.

How to fix it

php
if (is_string($code) && hash_equals($expected, $code)) { ... }

Further reading