Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-alrek committed Jul 3, 2016
1 parent e1d47f6 commit 5a9522b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
Hash and verify passwords hashed with PHP's built-in password_* functions

Designed to be future proof for new hashing algorithms.

Usage:

var Password = require("node-php-password");

var hash = Password.password_hash("password123", "PASSWORD_DEFAULT", { cost: 10 });
//hash: "$2y$10$8mNOnsos8qo4qHLcd32zrOg7gmyvfZ6/o9.2nsP/u6TRbrANdLREy"

console.log(Password.password_verify("password123", hash);
//true

var hash = $1$7576f3a00f6de47b0c72c5baf2d505b0
console.log(Password.password_needs_rehash(hash, "PASSWORD_DEFAULT");
//true

WARNING password_needs_rehash is currently not working
12 changes: 8 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ function password_hash(password, algorithm, options){
}

function password_needs_rehash(hash, algorithm, options){
var info = password_get_info(hash);
try{
var info = password_get_info(hash);
}catch(e){
return true;
}
if(typeof aliases[algorithm] !== 'undefined'){
algorithm = aliases[algorithm];
}
Expand All @@ -87,12 +91,12 @@ function password_needs_rehash(hash, algorithm, options){
if(algorithms[algorithm].name == info.algoName){
if(typeof options !== 'undefined' && typeof options.cost !== 'undefined'){
if(info.options.cost != options.cost){
return false;
return true;
}
}
return true;
return false;
}
return false;
return true;
}

function password_verify(password, hash){
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"version": "0.0.1",
"description": "A node compatibility layer to verify and hash php compatible password hashes",
"main": "index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/alrek-consulting/node-php-password.git"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand Down

0 comments on commit 5a9522b

Please sign in to comment.