From a1112988c4624219461acf8269058353203969c2 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 31 Jul 2018 14:37:39 -0400 Subject: [PATCH] null key checks --- src/services/totp.service.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/services/totp.service.ts b/src/services/totp.service.ts index 9b4437544d..293810112b 100644 --- a/src/services/totp.service.ts +++ b/src/services/totp.service.ts @@ -12,11 +12,14 @@ export class TotpService implements TotpServiceAbstraction { constructor(private storageService: StorageService, private cryptoFunctionService: CryptoFunctionService) { } async getCode(key: string): Promise { + if (key == null) { + return null; + } let period = 30; let alg: 'sha1' | 'sha256' | 'sha512' = 'sha1'; let digits = 6; let keyB32 = key; - if (key.indexOf('otpauth://') === 0) { + if (key.toLowerCase().indexOf('otpauth://') === 0) { const params = Utils.getQueryParams(key); if (params.has('digits') && params.get('digits') != null) { try { @@ -73,7 +76,7 @@ export class TotpService implements TotpServiceAbstraction { getTimeInterval(key: string): number { let period = 30; - if (key.indexOf('otpauth://') === 0) { + if (key != null && key.toLowerCase().indexOf('otpauth://') === 0) { const params = Utils.getQueryParams(key); if (params.has('period') && params.get('period') != null) { try {