jiangts / js-otp Goto Github PK
View Code? Open in Web Editor NEW100% Javascript Implementation of HOTP and TOTP for Two-Factor Authentication.
Home Page: https://jiangts.github.io/JS-OTP
License: MIT License
100% Javascript Implementation of HOTP and TOTP for Two-Factor Authentication.
Home Page: https://jiangts.github.io/JS-OTP
License: MIT License
Hi,
jsOTP.js Lack of credits and licence infos.
I added this in the file I use, inspired from jsOTP.min.js:
--- a/jsOTP.js
+++ b/jsOTP.js
@@ -1,3 +1,11 @@
+/*
+* File combining
+* (1) sha.js by Brian Turek 2008-2013 under BSD license
+* (2) and a modified js OTP implementation found on JSFiddle
+*
+* See https://github.com/jiangts/JS-OTP for more information
+*/
+
(function() {
var Hotp, Totp;
Hello,
Nice javascript. I receive an error when generating an hotp with a counter size > 127.
hotp.getOtp(secret,128) will fail: my console shows the following output:
URIError: malformed URI sequence
line 85 in Hotp.prototype.uintToString
For secret TCFBROLCJDXLCDQQY63MAOX6HXZPKR335YPAVAMADXAQ2PF2MBB7FQV2BT5Z5PWM
and timestamp 1525821908
, totp length 8
, the generated totp is 1
. Should be 01680911
.
The implementation for Base64ToHex in this project is broken for Base64 strings that do not amount to a multiply of eight.
Replacing base32tohex
in jsOTP.js
fixes those issues:
base32tohex(base32) {
let base32chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
let bits = [];
for (let i = 0; i < base32.length; i++) {
let intVal = base32chars.indexOf(base32.charAt(i).toUpperCase());
if (intVal === -1 || intVal === null) {
throw new Error("Invalid B64 char: " + base32.charAt(i));
}
let binaryRep = intVal.toString(2);
let diffLen = 5 - binaryRep.length;
for (let j = 0; j < diffLen; j++) {
bits.push("0");
}
for (let j = 0; j < binaryRep.length; j++) {
bits.push(binaryRep[j]);
}
}
let hexstr = "";
for (let i = 0; i < bits.length; i += 8) {
let binByte = bits.slice(i, i + 8).join("");
if (binByte.length < 8) {
continue;
}
let hexn = parseInt(binByte, 2).toString(16);
hexstr += hexn.length === 2 ? hexn : "0" + hexn;
}
return hexstr;
}
There's no code license, which means it's copyright infringement to actually use this library.
>> Uglifying source dist/jsOTP.js failed.
Warning: Uglification failed.
Unexpected token: name (Totp).
Line 4 in dist/jsOTP.js
Line 4 is:
Totp = class Totp
Hi, I'm trying to generate totp for mega.nz account which have 52 character secret. Google authenticator giving totp fine. But this js not working.
Can you look into it.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.