From 4c7db622903b99241d9c338b83c8691d28c2040b Mon Sep 17 00:00:00 2001 From: Ali Heydari Date: Sun, 18 Dec 2022 20:04:32 +0000 Subject: [PATCH] bugfix(scripts): import otp error handling --- app/scripts/util/data/otp.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/scripts/util/data/otp.js b/app/scripts/util/data/otp.js index 2566157c..1fe477dc 100644 --- a/app/scripts/util/data/otp.js +++ b/app/scripts/util/data/otp.js @@ -3,13 +3,13 @@ import { Logger } from 'util/logger'; const logger = new Logger('otp'); const Otp = function (url, params) { - if (['hotp', 'totp'].indexOf(params.type) < 0) { + if (['hotp', 'totp'].indexOf(params.type.toLowerCase()) < 0) { throw 'Bad type: ' + params.type; } if (!params.secret) { throw 'Empty secret'; } - if (params.algorithm && ['SHA1', 'SHA256', 'SHA512'].indexOf(params.algorithm) < 0) { + if (params.algorithm && ['SHA1', 'SHA256', 'SHA512'].indexOf(params.algorithm.toUpperCase()) < 0) { throw 'Bad algorithm: ' + params.algorithm; } if (params.digits && ['6', '7', '8'].indexOf(params.digits) < 0) { @@ -18,13 +18,13 @@ const Otp = function (url, params) { if (params.type === 'hotp' && !params.counter) { throw 'Bad counter: ' + params.counter; } - if ((params.period && isNaN(params.period)) || params.period < 1) { + if ((params.period && Number.isNaN(params.period)) || params.period < 1) { throw 'Bad period: ' + params.period; } this.url = url; - this.type = params.type; + this.type = params.type.toLowerCase(); this.account = params.account; this.secret = params.secret; this.issuer = params.issuer;