Coder Social home page Coder Social logo

xarenard / simpleotp Goto Github PK

View Code? Open in Web Editor NEW
9.0 2.0 3.0 419 KB

Simple OTP implementation in node.js according to rfc 4996 and rfc 6238

License: MIT License

JavaScript 100.00%
totp hotp otp nodejs nodejs-modules node-js hmac rfc-6238 rfc-4226

simpleotp's People

Contributors

xarenard avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

simpleotp's Issues

Token code not zero-padded to correct length

if (token.length < num_digits) {

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.

sha1 algorithm only worked

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;

};

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.