feat: fix validation generate otp

pull/148/head
Firman Ramdhani 2025-06-10 15:17:35 +07:00
parent 8497a5779d
commit 16df6945b7
1 changed files with 8 additions and 3 deletions

View File

@ -38,10 +38,14 @@ export class OtpService {
return Object.values(counts).some((count) => count > 2);
}
private hasMatchLength(str: string) {
private hasNoMatchLength(str: string) {
return str.length !== this.otpLength;
}
private hasStartWithZero(str: string) {
return str.split('')[0] === '0';
}
public generateSecureOTP(): string {
let otp: string;
@ -50,11 +54,12 @@ export class OtpService {
Math.floor(Math.random() * 10).toString(),
).join('');
} while (
this.hasMatchLength(otp) ||
this.hasNoMatchLength(otp) ||
this.hasSequentialDigits(otp) ||
this.hasRepeatedDigits(otp) ||
this.isPalindrome(otp) ||
this.hasPartiallyRepeatedDigits(otp)
this.hasPartiallyRepeatedDigits(otp) ||
this.hasStartWithZero(otp)
);
return otp;
}