validateOTPLength function
Validates OTP length within configured bounds. Returns the validated length.
Implementation
int validateOTPLength(
int? length, {
int defaultValue = 6,
bool? enableSecurity,
}) {
final shouldValidate = enableSecurity ?? OTPSecurityConfig.enforceValidation;
if (length == null) return defaultValue;
if (!shouldValidate) return length;
if (length > OTPSecurityConfig.maxOTPLength) {
if (OTPSecurityConfig.enableSecurityLogging) {
debugPrint(
'[SAC OTP Security] Length $length exceeds max ${OTPSecurityConfig.maxOTPLength}',
);
}
return OTPSecurityConfig.maxOTPLength;
}
if (length < OTPSecurityConfig.minOTPLength) {
if (OTPSecurityConfig.enableSecurityLogging) {
debugPrint(
'[SAC OTP Security] Length $length below min ${OTPSecurityConfig.minOTPLength}',
);
}
return OTPSecurityConfig.minOTPLength;
}
return length;
}