constantTimeVerification static method Null safety
Allows you to compare 2 codes in constant time, to mitigate timing attacks for secure codes.
This function takes 2 codes in string format.
Implementation
static bool constantTimeVerification(
final String code, final String othercode) {
if (code.length != othercode.length) {
return false;
}
var result = true;
for (var i = 0; i < code.length; i++) {
// Keep result at the end otherwise Dart VM will shortcircuit on a result thats already false.
result = (code[i] == othercode[i]) && result;
}
return result;
}