diff --git a/src/core/helpers/otp/otp-service.ts b/src/core/helpers/otp/otp-service.ts index 0ba5e26..0b4e3e1 100644 --- a/src/core/helpers/otp/otp-service.ts +++ b/src/core/helpers/otp/otp-service.ts @@ -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; }