xarenard / simpleotp Goto Github PK
View Code? Open in Web Editor NEWSimple OTP implementation in node.js according to rfc 4996 and rfc 6238
License: MIT License
Simple OTP implementation in node.js according to rfc 4996 and rfc 6238
License: MIT License
fix this function
add const algorithm to options to create the same validate token
Hotp.prototype.validate = function (data) {
const expectedToken = data.token;
const counter = data.counter;
const secret = data.secret;
const window = data.window;
const num_digits = this.options.num_digits;
**const algorithm = data.algorithm;**
let isValid = false;
let window_frame = counter + (window || 0);
let i = counter;
while(i <= window_frame && !isValid){
let token = this.createToken({num_digits: num_digits,counter:i,secret: secret,encoding: data.encoding ,**algorithm: data.algorithm**});
if (token.toString() === expectedToken) {
isValid = true;
}
i++;
}
return isValid;
};
Line 76 in c974078
Hi @xarenard ,
I noticed that tokens that begin with a leading 0
are sometimes not the correct length.
The problem is that the if statement in the referenced line will only add one zero.
If there are two or more leading zeros required, the generated code is not the correct length.
// Sample rfc_6238 test data - should be of length "8"
const testDatas = [
// ...
{ seconds: 3060, algorithm: 'sha1', expected_token: '00629694' },
{ seconds: 4620, algorithm: 'sha256', expected_token: '00836417' },
{ seconds: 5100, algorithm: 'sha512', expected_token: '00458766' }
]
I can submit a PR if you'd like, but it should just be a matter of updating this if
statement to a while
loop.
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.