Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

argon2-pass

DrBarnabus25MITdeprecated1.0.2TypeScript support: included

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

State of the art password hashing and one time password reset token generation module written in TypeScript for nodejs.

secure, password, hashing, libsodium, sodium, crypto, security, argon, argon2, argon2id, reset, onetime, token, typescript, argon2 password, secure password, argon2id password, password hasing, password hasher, password security, one time authentication, one time authentication code, one time key, cryptography

readme

NPM Version NPM Downloads Build Status Test Coverage Dependencies devDependencies Known Vulnerabilities Code Quality

Introduction

SecurePass (argon2-pass) is a module for the creation of hashes from passwords, allowing you to store passwords securely. The module also provides a facility for the generation and verification of one time authentication tokens for use in your own password reset flows. This module is a wrapper for libsodium's implementation of the Argon2ID password hashing algorithm and Poly1305.

Features

  • Uses the state of the art, secure modern password hashing algorithm Argon2ID.
  • Uses Buffer's for safer memory management.
  • Uses static functions for basic operations, so you don't have to create a new instance every time.
  • asynchronous functions are defined to work with async/await, promises and callbacks. Synchronous versions are also available just in-case you don't want your hashing and verification to be asynchronous.
  • Allows for generation of one time use authentication tokens to be used in your own password reset flow.
  • Easily configurable work factors, allowing you to increase the security of your hashes over time.
  • Three default difficulty configurations for password hashing, as defined in libsodium's implementation. Allowing you to configure your security level based on some recommended predefined values.
  • Simple rehashing of passwords you are already storing. Allowing you to improve the security of your hashes over time.
  • The module is written in typescript and ships with a type definition file by default.

Installation

Install argon2-pass using yarn:

yarn add argon2-pass

Or via npm:

npm install argon2-pass

Usage

Basic Usage Information:

import { SecurePass, VerificationResult } from 'argon2-pass';

async function main() {
  // Create a new instance of SecurePass. Optional difficulty configurations can be passed in here.
  const sp = new SecurePass();

  // Passwords and Hashes are stored as buffers internally.
  const password = Buffer.from('SamplePassword');
  const hash = await sp.hashPassword(password);

  // Hash Verification returns an enumerator for easy validation of passwords against hashes.
  const result = await sp.verifyHash(password, hash);
  if (SecurePass.isInvalidOrUnrecognized(result)) { 
    console.log('Hash not created by SecurePass or invalid');
  } else if (SecurePass.isInvalid(result)) {
    console.log('Password not valid when compared with supplied hash');
  } else if (SecurePass.isValid(result)) {
    console.log('Password and Hash are a match');
  } else if (SecurePass.isValidNeedsRehash(result)) {
    console.log('Password and Hash are a match, but the security of the hash could be improved by rehashing.');
  }

  // Generation of one time authentication codes.
  const otac = SecurePass.generateOneTimeAuthCode(Buffer.from('DrBarnabus'));

  // Validate the one time authentication code with the random key.
  // The random key should never be sent with the code, and should be kept secret.
  if (SecurePass.verifyOneTimeAuthCode(otac.code, otac.key)) {
    console.log('OTA Code is valid!');
  } else {
    console.log('OTA Code is invalid!');
  }
}

// Call the async function defined above to run the example.
main();

For full documentation, please refer to the full documentation site. The documentation was generated automaticaly with TypeDoc.

Testing

This package is configured with jest tests, these tests ensure that the module is working correctly and as specified as well as generating code coverage reports to ensure every line of code is covered by a unit test.

To run the jest tests manualy run the test script defined in package.json:

yarn test

This module also has the following automated testing:

  • CI Builds on Travis.
  • Code Coverage Reports on CodeCov.
  • Dependency Update Checks on david-dm.
  • Dependency Vulnerabilities Checks on snyk.
  • Automated Code Review and Quality Report on codacy.

Acknowledgements

  • Special thanks to the creators of libsodium and sodium-native both of which are used extensively in this package, and without which the creation of this module wouldn't have been possible.

Licence

Licensed under MIT.

Copyright (C) 2018 DrBarnabus

changelog

Changelog

All notable changes to this project will be documented in this file. This project adheres to Semantic Versioning.

1.0.2 - 2019-08-02

Updated package dependencies and re-released.

1.0.1 - 2018-12-12

Updated package dependencies and re-released.

1.0.0 - 2018-09-19

First major release of the package. This version will receive full support if any issues are identified as it is no longer deemed to be a "development version".

Added

  • Added a check in verifyOneTimeAuthCode() to validate that the auth code is in the correct format before attempting to separate the code into mac and message. The function will now return false if the code doesn't pass the validation instead of attempting to verify.

[0.2.2] - 2018-09-10

Added

  • Added convenience functions to test if a VerificationResult is a specific type. These are; isInvalidOrUnrecognized(), isInvalid(), isValid() and isValidNeedsRehash(). These functions will return true if the enumeration value matches the tested value.

0.2.1 - 2018-09-09

Removed

  • Removed development console.log calls from the module, these were left in after testing the changes to static readonly values.

0.2.0 - 2018-09-08

Added

  • Added JSDoc comments to all functions and important objects. This was then used with the TypeDoc module to generate a documentation site for the package.
  • Added synchronous versions of hash and verify. hashPasswordSync() and verifyHashSync().
  • Added get and set functions for MemLimit. MemLimit() and MemLimit(newValue).
  • Added get and set functions for OpsLimit. OpsLimit() and OpsLimit(newValue).

Changed

  • static readonly configuration default values are now set to their value manually. Previously they were just "re-exports" of sodium-native's constants.

Removed

  • Possibly Breaking Change: Removed getMemLimit() and getOpsLimit() functions, replaced with getters and setters as detailed above.

0.1.3 - 2018-09-06

Added

  • Added internal functions to convert buffers to url-safe base64 and back again.
  • Added functions to generate and verify one time authentication buffers. Generates a mac from a supplied message using a random key.
  • Added convenience function to generate and verify one time authentication codes, the mac and message is returned as base64 string.

Changed

  • Package npm/yarn name changed to argon2-pass as secure-pass was too close to another package name.

0.1.2 - 2018-09-06

Fixed

  • Moved SecurePassError and SecurePassOptionsError into a new file.

0.1.1 - 2018-09-06

Fixed

  • Fixed missing export SecurePassError.

0.1.0 - 2018-09-06

Added

  • Added constants for all recommended, minium, maxium and default configuration values.
  • Added get functions for the currently configured memory limit and operations limit.
  • Added a custom error class SecurePassOptionsError that is thrown if an error occurs during options validation.
  • Added hashPassword() function, the function takes a password in as a buffer and provides the hashed output. The function can work with any of the following return methods; async/await, promise or callback.
  • Added VerificationResult enumeration to serve as the response to the hash verification function.
  • Added verifyHash() function, the function takes a password and a hash as buffers and provides a VerificationResult as an output. The function can work with any of the following return methods; async/await, promise or callback.