codeauth

1.1.0 • Public • Published

CodeAuth


CodeAuth is a simple Node.js package that makes it easy to implement a confirmation code system to a project.

It's easy to get started, all CodeAuth needs is a MySQL database.

Create a simple project

var auth = require('codeauth');
 
auth.mysql({ // Create MySQL connection
    host: "localhost",
    user: "root",
    password: "mysql",
    database: "codeauth",
    table: "codes"
}, function() {
    callback(); // After connection is made + succesful
});

Generate a new code

function callback() {
    var userCode = new auth.code( "Test User", 6 ); // Generate new 6 digit long code for use only by user "Test User"
    userCode.store(); // Stores code hash in table
    somehowReplyBackToUser(userCode.code); // Send 6 digit code back to user to enter, could be a text message or email
}

Check if user entered a correct code

auth.check( "Test User", %code the user entered%, function( result ){ 
    if (result) somehowReplyBackToUser("Success!");
    else        somehowReplyBackToUser("Failure!");
    auth.close(); // Close MySQL Connection
});

Dependencies (2)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i codeauth

    Weekly Downloads

    0

    Version

    1.1.0

    License

    ISC

    Last publish

    Collaborators

    • toish