passhash-auth

Module to be used to read in hashed passwords generate by passhash. This can be used as a replacement for htpasswd for web apps or easy authentication for standalone apps.

npm install passhash-auth
1 downloads in the last day
13 downloads in the last week
42 downloads in the last month

passhash-auth

Module to be used to read in hashed passwords generated by passhash. This can be used as a replacement for htpasswd for web apps or easy authentication for standalone apps.

Usage

npm install passhash-auth

then

var PasshashAuth = require('passhash-auth')
var auth = new PasshashAuth('./passhashauth.txt');

Functions

new PasshashAuth(databaseFileName)

Return a new object that can be used to authenticate usernames against the database given

The file should contain lines using the default output format of passhash. For reference:

{username}:{salt}:{hash}:{iterations}

.isUser(username)

Checks if a given username is valid. Returns a boolean.

.checkHashMatch(username, password)

Checks if the given username and password are valid. Returns a boolean.

Example

For this example we will assume the user name and password were obtained from a secure source such as a SSL socket. Due to the checkHashMatch function returning a boolean, you can have it execute anything you want depending on the return value. For our example it will print to stdout either match or nonmatch.

var PasshashAuth = require('passhash-auth');
var auth = new PasshashAuth(__dirname + '/test_auth');

var user1 = 'test';
var pass1 = 'correctPassword';

if (auth.checkHashMatch(user1, pass1)) {
    console.log('match');
} else {
    console.log('nonmatch');
}

This outputs:

match

License

MIT

npm loves you