feat: fix validation generate otp
parent
8497a5779d
commit
16df6945b7
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue