Have ideas to improve npm?Join in the discussion! »

    totp-generator
    DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/totp-generator package

    0.0.9 • Public • Published

    totp-generator

    Test Code Climate Test Coverage npm Version

    totp-generator lets you generate TOTP tokens from a TOTP key

    How to use

    const totp = require("totp-generator");
    
    const token = totp("JBSWY3DPEHPK3PXP");
    
    console.log(token); // prints a 6-digit time-based token based on provided key and current time

    Default token settings

    • SHA-1
    • 30-second epoch interval
    • 6-digit tokens

    Custom token settings

    Settings can be provided as an optional second parameter:

    const totp = require("totp-generator");
    
    const token = totp("JBSWY3DPEHPK3PXP", { digits: 8 });
    console.log(token); // prints an 8-digit token
    
    const token = totp("JBSWY3DPEHPK3PXP", { algorithm: "SHA-512" });
    console.log(token); // prints a token created using a different algorithm
    
    const token = totp("JBSWY3DPEHPK3PXP", { period: 60 });
    console.log(token); // prints a token using a 60-second epoch interval
    
    const token = totp("JBSWY3DPEHPK3PXP", {
    	digits: 8,
    	algorithm: "SHA-512",
    	period: 60,
    });
    console.log(token); // prints a token using all custom settings combined

    What do I use this library for?

    • TOTP generation
    • E2E tests (where you need to login with 2-factor authentication)

    Install

    npm i totp-generator

    DownloadsWeekly Downloads

    20,377

    Version

    0.0.9

    License

    MIT

    Unpacked Size

    8.13 kB

    Total Files

    12

    Last publish

    Collaborators

    • avatar