Giter Site home page Giter Site logo

password-hash's Introduction

Node PasswordHash module

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

See original PHPass at https://www.openwall.com/phpass/.

Installation

npm install node-phpass

Password hash

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 which 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

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 which 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.

License

THE MIT LICENSE

Copyright (c) 2018 Glauber Portella [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

password-hash's People

Contributors

donguks avatar glauberportella avatar leleofg avatar tombaileywzd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

password-hash's Issues

International characters are causing the hash to not be compatible with WP hash

When I use WP to hash the password like this: aląmakota, I'll get some hash. When I take this hash and compare it against the aląmakota using this module, the result is false which means the password is incorrect. When I compare it using WP PasswordHash class, it says it's ok.
The same is in the other way. When I hash aląmakota using this module, I'll get some hash. When I take this hash and compare it using WP, the result is false.

All other passwords are OK both in WP and this module.

Error: ENOENT: no such file or directory, open 'c:\dev\urandom'

Error: ENOENT: no such file or directory, open 'c:\dev\urandom'
Emitted 'error' event on ReadStream instance at:
    at internal/fs/streams.js:121:12
    at FSReqCallback.oncomplete (fs.js:157:23) {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'open',
  path: 'c:\\dev\\urandom'
}

bcrypt dependency fails on AWS Lambda

The AWS Lambda function with both password-hash and password-hash-leo dependencies gets an error when is invoked:

{
    "errorType": "Error",
    "errorMessage": "package.json does not exist at /package.json",
    "stack": [
        "Error: package.json does not exist at /package.json",
        "    at Object.exports.find (/var/task/node-functions/lambda/cognito/handleUserMigrationAuthentication.js:37011:15)",
        "    at Object.<anonymous> (/var/task/node-functions/lambda/cognito/handleUserMigrationAuthentication.js:176283:27)",
        "    at Object.<anonymous> (/var/task/node-functions/lambda/cognito/handleUserMigrationAuthentication.js:176516:30)",
        "    at __webpack_require__ (/var/task/node-functions/lambda/cognito/handleUserMigrationAuthentication.js:20:30)",
        "    at Object.<anonymous> (/var/task/node-functions/lambda/cognito/handleUserMigrationAuthentication.js:84834:16)",
        "    at __webpack_require__ (/var/task/node-functions/lambda/cognito/handleUserMigrationAuthentication.js:20:30)",
        "    at Module.exports.__esModule (/var/task/node-functions/lambda/cognito/handleUserMigrationAuthentication.js:85169:21)",
        "    at __webpack_require__ (/var/task/node-functions/lambda/cognito/handleUserMigrationAuthentication.js:20:30)",
        "    at /var/task/node-functions/lambda/cognito/handleUserMigrationAuthentication.js:84:18",
        "    at Object.<anonymous> (/var/task/node-functions/lambda/cognito/handleUserMigrationAuthentication.js:87:10)",
        "    at Module._compile (internal/modules/cjs/loader.js:778:30)",
        "    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)",
        "    at Module.load (internal/modules/cjs/loader.js:653:32)",
        "    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)",
        "    at Function.Module._load (internal/modules/cjs/loader.js:585:3)",
        "    at Module.require (internal/modules/cjs/loader.js:692:17)"
    ]
}

After some debugging, I could fix an issue with replacing bcrypt dependency with bcryptjs. The reason why it helped is bcrypt uses OS functions that don't exist for a Lambda environment. The bcrypjs on the other hand doesn't require that but it's a little bit slower. So eventually I have to use the raw source file with that workaround. I know bcrypt was updated to 5.0.0 version but that didn't help. Also, I couldn't reproduce the issue locally.

New release

Can you please make a new release with the bcrypt #5 update?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.