Skip to content

Commit

Permalink
added example on README
Browse files Browse the repository at this point in the history
  • Loading branch information
glauberportella committed Nov 7, 2018
1 parent 6ffdccf commit 23538c7
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,61 @@

A port of Wordpress wp-includes/class-phpass.php class used to hash passwords.

See original PHP class at [https://www.openwall.com/phpass/].
See original PHP class PHPass at (https://www.openwall.com/phpass/)[https://www.openwall.com/phpass/].

# Installation

`npm install node-phpass`

# Password hash

```js
const PasswordHash = require('node-phpass').PasswordHash;
const CRYPT_BLOWFISH = require('node-phpass').CRYPT_BLOWFISH;
const CRYPT_EXT_DES = require('node-phpass').CRYPT_EXT_DES;
// or
// const { PasswordHash, CRYPT_BLOWFISH, CRYPT_EXT_DES } = require('node-phpass')

const len = 8;
const portable = true;
// major PHP version, 5 or 7, as it is a port of PHPass PHP class we rely
// on php version on gensalt_private() method, it is an optional constructor
// argument wich defaults to 7
const phpversion = 7;

const hasher = new PasswordHash(len, portable, phpversion);
console.log('Hashing 123456 string');
hasher.HashPassword('123456').then(hash => console.log('Private hash: ', hash));
hasher.HashPassword('123456', CRYPT_BLOWFISH).then(hash => console.log('BCrypt hash: ', hash));
hasher.HashPassword('123456', CRYPT_EXT_DES).then(hash => console.log('DES hash: ', hash));
```

# Verify a hash

```js
const PasswordHash = require('node-phpass').PasswordHash;
// or
// const { PasswordHash } = require('node-phpass')

const len = 8;
const portable = true;
// major PHP version, 5 or 7, as it is a port of PHPass PHP class we rely
// on php version on gensalt_private() method, it is an optional constructor
// argument wich defaults to 7
const phpversion = 7;

const hasher = new PasswordHash(len, portable, phpversion);

const storedhash = '$P$BVaXtDXwf/ceSVp8VpLKx8bS2Y4O5F/';
const storedhash2 = '$P$BVaXtDXwf/ceSVp8VpLKx8bS2Y4O5E/';
const password = '123456';
const valid = hasher.CheckPassword(password, storedhash);
const invalid = hasher.CheckPassword(password, storedhash2);

console.log(valid ? 'OK' : 'INVALID');
console.log(invalid ? 'OK' : 'INVALID');
```

# Contributing

Any help on testing and improvements in this class is welcome. Fork the repo and send a PR.
Expand Down

0 comments on commit 23538c7

Please sign in to comment.