hash_equals determines whether string values are equal

hash_equals

is a string comparison that prevents timing attacks, so what is a timing attack? For example, in this code we use

        $verifyData['code'] == $request->verification_code

For comparison, then the two strings are compared one by one from the first bit, and if they are different, they will return false immediately, then by calculating the speed of the return, you can know which bit is different from the beginning, so that the movie is realized. A common scenario for bit-by-bit cracking of passwords. Using hash_equals to compare two strings, regardless of whether the strings are equal, the time consumption of the function is constant, which can effectively prevent timing attacks.

So it is recommended to use

         hash_equals($verifyData['code'], $request->verification_code)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325500111&siteId=291194637