Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bahamas10/node-hashp
Manage users and hashed passwords using sha-512 with variable iterations
https://github.com/bahamas10/node-hashp
Last synced: 15 days ago
JSON representation
Manage users and hashed passwords using sha-512 with variable iterations
- Host: GitHub
- URL: https://github.com/bahamas10/node-hashp
- Owner: bahamas10
- Created: 2015-10-08T05:58:16.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-07-18T20:20:25.000Z (over 6 years ago)
- Last Synced: 2024-11-14T05:42:23.854Z (about 2 months ago)
- Language: JavaScript
- Homepage: http://bahamas10.github.io/node-hashp/
- Size: 30.3 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
node-hashp
==========Manage users and hashed passwords using sha-512 with variable iterations
Note: to create `HashP` formatted lines you can use http://bahamas10.github.io/node-hashp/ -
all processing is done on the client side.Usage
-----### `hashp.createUserHash(user, password[, opts={}])`
Create a `hashp` formatted hashed password string
``` js
var hashp = require('hashp');
var line = hashp.createUserHash('dave', 'foobar');
// => "dave:NUcDl5mR6T:lKjPCs5Z1+Uwl0gxYU/AWIKbTV4i8bsWlHeE5fYYwW8Tt/O6YtohJasjER5kIb8RKtniyLi0ppxn3wXQyaxGzg==:68"
````opts`
- `opts.algorithm` - hash algorithm to use, defaults to `sha512`
- `opts.format` - string format, defaults to `{{user}}:{{salt}}:{{hash}}:{{iterations}}`
- `opts.iterations` - number of iterations, defaults to a random number between 50 and 150
- `opts.salt` - salt to hash with, defaults to something random### `var hp = new hashp.HashP(s, opts)`
Create a `HashP` object with a given string of newline separated hashed password strings
- `s` - the string of hashp file format
- `opts.duplicates` - how to handle duplicate usernames, possibilities are:- `opts.duplicates` === `ignore`: (default) last username in the text file wins
- `opts.duplicates` === `throw`: throw an error if a duplicate username is fuond
- `opts.duplicates` === `allow`: allows duplicates usernames (stored as an array)`passwords.txt`
```
# some comment
dave:0Hmg1NlFBz:AoUd5RaBWFvGZD6oD+KZqGBExFH4fpvr4jtfDBsW+dBxYibzo8GwomNzAtFFbaydzN1BU67TfpksCnW9uyFI7Q==:86# something else
skye:SJSsH5+g6A:4ESGl7LUyuaVdB2SH4laTrOKHyZL/pDhKCIb0AHbiWeJF7h5bPJS8Oxe5sm6Gmb6j2kMIKnD4YK+ceW3Wq7f3A==:95
`````` js
var hashp = require('hashp');
var fs = require('fs');var data = fs.readFileSync('./passwords.txt', 'utf8');
var hp = new hashp.HashP(data);
```### `hp.exists(user)`
Check if a user exists
``` js
hp.exists('dave');
// => truehp.exists('john');
// => false
```### `hp.checkMatch(user, password)`
Check if a user/pass combo matches
``` js
hp.checkMatch('dave', 'foo');
// => true
hp.checkMatch('dave', 'bar');
// => false
hp.checkMtach('john', 'bar');
// => false
```---
These functions are exposed but probably don't need to be called directly
### `hashp.hashPassword(password[, opts={}])`
Hash a password, opts is the same createUserHash
### `hashp.generateSalt([opts={}])`
Generate a random salt, opts is the same createUserHash
CLI Usage
---------$ echo -n password | hashp dave
dave:RYueIcbr7E:CaNK4tuamiyOSz3zVzBaMNTxq2+E2XlPlo9/XpQ+agcmIJnL32OPh97BUrlkBDEFn7SofQNZWlCaQnVFVfGz8w==:65Installation
------------Use as a module
npm install hashp
Use as a CLI tool
npm install -g hashp
License
-------MIT License