From cd19e0c9e4f6555d122886328977c2d8df74673e Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 13 Jul 2017 14:45:57 -0400 Subject: [PATCH] totp code updates --- src/app/directives/totpDirective.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/app/directives/totpDirective.js b/src/app/directives/totpDirective.js index 5b3d2dfb16..332b9ebb4b 100644 --- a/src/app/directives/totpDirective.js +++ b/src/app/directives/totpDirective.js @@ -56,11 +56,25 @@ angular } var b32tohex = function (s) { + s = s.toUpperCase(); + var cleanedInput = ''; + for (var i = 0; i < s.length; i++) { + if (b32Chars.indexOf(s[i]) < 0) { + continue; + } + + cleanedInput += s[i]; + } + s = cleanedInput; + var bits = ''; var hex = ''; for (var i = 0; i < s.length; i++) { - var val = b32Chars.indexOf(s.charAt(i).toUpperCase()); - bits += leftpad(val.toString(2), 5, '0'); + var byteIndex = b32Chars.indexOf(s.charAt(i)); + if (byteIndex < 0) { + continue; + } + bits += leftpad(byteIndex.toString(2), 5, '0'); } for (var i = 0; i + 4 <= bits.length; i += 4) { var chunk = bits.substr(i, 4); @@ -131,13 +145,13 @@ angular var tick = function (scope) { $timeout(function () { var epoch = Math.round(new Date().getTime() / 1000.0); - var mod = (epoch % 30); + var mod = epoch % 30; var sec = 30 - mod; scope.sec = sec; scope.dash = (2.62 * mod).toFixed(2); scope.low = sec <= 7; - if (epoch % 30 == 0) { + if (mod == 0) { updateCode(scope); } });