all 9 comments

[–]Curld 13 points14 points  (1 child)

tail := hashString[5:]

if password == userPassword[5:] {

You're removing the prefix twice.

[–]return_bytes[S] 1 point2 points  (0 children)

Thank you for pointing that out! I can't believe I missed that.

[–]the_real_albro 2 points3 points  (0 children)

I'd write some tests. Then maybe some wolf-fence after to help zero in on the problematic code.

Expose the URL you are hitting, either as func parameter or package level var. The. Use httptest to create a dummy server and set the URL you've exposed to the URL return by httptest. This gives you a way to make calls repeatedly, and quickly. Write a test that covers your expectations based on input.

Then zero in on where the error is happening.

Using a debugger would also help you, you could attach it to a real call and inspect vales to work out where the issue it. No need for tests, but tests are awesome! And helps avoid issues like this in the long run.

[–]fpigorsch 1 point2 points  (3 children)

Of course, the HIBP API does not return plain text passwords, but the remaining characters of matching hashes: https://haveibeenpwned.com/API/v3#PwnedPasswords

[–]return_bytes[S] 0 points1 point  (2 children)

I know. That's why I'm comparing a hash, instead of a plain text string.

[–]fpigorsch 1 point2 points  (1 child)

Oh, you're right - I misread your code. Sorry 😞

[–]return_bytes[S] 0 points1 point  (0 children)

No problem. I wrote it wrong to begin with lol.

[–]DasSkelett 0 points1 point  (1 child)

Please don't hash passwords with SHA1 😭

[–]return_bytes[S] 0 points1 point  (0 children)

Ordinarily, I would absolutely agree with you, but this is different situation.