Compare values does not seem to be working

I have coded a dummy 6 digits number and asking users to input the same digits and compares them but it doesn’t seems to work.

The catch is that the 6 digits generated is hashed with SHA256 and then converted to Base64…

However, the generated digits and the input seems to be returning 2 different results of the hashed string… Curious if there is something I have overlooked…

Here is the code in JSFiddle:

let otpValue = Math.floor(100000 + Math.random() * 900000);

and

var otpInput = document.getElementById('otp').value;

What data types are each of those? Do different data types, even if they seem to contain the same value, hash the same way?

I’d force the first one to match the type of the second. When I do that, your code works for me.

1 Like

Thanks for the quick reply and hint. :sweat_smile:

Now I see where my mistakes is now.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.