> NOTE In general, it's not possible to prevent length leaks. So it's OK to leak the length. I would imagine that you can prevent length leaks by looping through the characters of the known value and then returning that comparison with an additional check of length. function timingSafeEquals($safe, $user) { $safeLen = strlen($safe); $userLen = strlen($user); $result = 0; for ($i = 0; $i
The for loop duration here will vary depending on the length of the string
But imagine the loop would be the string we know (i.e. the password). Looping through the 10-character pass should be identical every time, regardless of what the user entered.