Skip to content

Instantly share code, notes, and snippets.

@kylec32
Created January 31, 2022 02:21
Show Gist options
  • Save kylec32/508da451cb2207455485a4a82602a590 to your computer and use it in GitHub Desktop.
Save kylec32/508da451cb2207455485a4a82602a590 to your computer and use it in GitHub Desktop.
Timing Side-Channel Mitigated Password Checker
private static boolean verifyPassword(String realPassword, String providedPassword) {
if (realPassword.length() != providedPassword.length()) {
return false;
}
int result = 0;
for (int i = 0; i < realPassword.length(); i++) {
result |= realPassword.charAt(i) ^ providedPassword.charAt(i);
}
return result == 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment