mirror of
https://github.com/seiichiro0185/sailotp.git
synced 2024-11-22 15:49:43 +00:00
Catch error from invalid secrets
This commit is contained in:
parent
50770f0799
commit
ef1b5ad51d
1 changed files with 11 additions and 7 deletions
|
@ -75,6 +75,7 @@ function calcOTP(secret) {
|
||||||
// Get last full 30 / 60 Seconds and convert to HEX
|
// Get last full 30 / 60 Seconds and convert to HEX
|
||||||
var time = leftpad(dec2hex(Math.floor(epoch / 30)), 16, '0');
|
var time = leftpad(dec2hex(Math.floor(epoch / 30)), 16, '0');
|
||||||
|
|
||||||
|
try {
|
||||||
// Calculate the SHA-1 HMAC Value from time and key
|
// Calculate the SHA-1 HMAC Value from time and key
|
||||||
var hmacObj = new SHA.jsSHA(time, 'HEX');
|
var hmacObj = new SHA.jsSHA(time, 'HEX');
|
||||||
var hmac = hmacObj.getHMAC(key, 'HEX', 'SHA-1', "HEX");
|
var hmac = hmacObj.getHMAC(key, 'HEX', 'SHA-1', "HEX");
|
||||||
|
@ -84,6 +85,9 @@ function calcOTP(secret) {
|
||||||
|
|
||||||
var otp = (hex2dec(hmac.substr(offset * 2, 8)) & hex2dec('7fffffff')) + '';
|
var otp = (hex2dec(hmac.substr(offset * 2, 8)) & hex2dec('7fffffff')) + '';
|
||||||
otp = (otp).substr(otp.length - 6, 6);
|
otp = (otp).substr(otp.length - 6, 6);
|
||||||
|
} catch (e) {
|
||||||
|
otp = "Invalid Secret!"
|
||||||
|
}
|
||||||
|
|
||||||
// return the calculated token
|
// return the calculated token
|
||||||
return otp;
|
return otp;
|
||||||
|
|
Loading…
Reference in a new issue