codeauth
v1.1.0
Published
Creates a random number and stores it securly for use in 2 factor authentication.
Downloads
5
Maintainers
Readme
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
});