sn-auth

Authentication primitives for node.js applications

Usage no npm install needed!

<script type="module">
  import snAuth from 'https://cdn.skypack.dev/sn-auth';
</script>

README

sn-auth

Basic Authentication Middleware

Introduction

The sn-auth package provides a simple interface into the crypto.pbekdf2 function suitable for use with the sn-persist package. It provides a simplified interface to create a hashed password entry and to validate a password.

Installation

The simplest way to install the package is via npm:

    npm install sn-auth

Or via GIT:

    git clone git@github.com:smithee-us/sn-auth.git

Usage

To create a password entry, create a new instance of the pbkdf2 object, then call the generateSecret() function:

    var pbkdf2 = require( 'sn-auth' ).pbkdf2;
    var password_entry = new pbkdf2( { password: "whatever" }, function( err ) {
      if( ! err ) {
        this.generateSecret( function( err ) {
          console.log( this );
        } );
      }
    } );

To validate a trial password, do this:

    password_entry.validate( "whatever", function( err, valid ) {
      if( valid ) {
        console.log( "password matches" );
      } else {
        console.log( "password doesn't match" );
      }
    } );