Skip to content

Commit

Permalink
Merge pull request #4 from rgeber/master
Browse files Browse the repository at this point in the history
Added CRYPT support to hash generator
  • Loading branch information
andris9 committed Mar 20, 2013
2 parents da9114b + ff18c38 commit a20a282
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
10 changes: 7 additions & 3 deletions package.json
Original file line number Original file line Diff line number Diff line change
@@ -1,15 +1,19 @@
{ {
"name" : "pass", "name" : "pass",
"version": "0.1.1", "version": "0.1.2",
"main" : "./index", "main" : "./index",
"description": "Apache htpasswd password generator/validator", "description": "Apache htpasswd password generator/validator",
"author" : "Andris Reinman", "author" : "Andris Reinman",
"maintainers":[ "maintainers":[
{ {
"name":"andris", "name":"andris",
"email":"andris@node.ee" "email":"andris@node.ee"
},
{
"name":"rgeber",
"email":"geber@b1-systems.de"
} }
], ],
"repository" : { "repository" : {
"type" : "git", "type" : "git",
"url" : "http://github.com/andris9/pass" "url" : "http://github.com/andris9/pass"
Expand Down
26 changes: 18 additions & 8 deletions pass.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -15,16 +15,26 @@ exports.generate = function(password, callback, param){
var algorithm = param.algorithm ? param.algorithm : 'sha1'; var algorithm = param.algorithm ? param.algorithm : 'sha1';
var digest = param.digest ? param.digest : 'base64'; var digest = param.digest ? param.digest : 'base64';


var hash_prefix = {sha1: '{SHA}', md5: '$apr1$'}; var hash_prefix = {sha1: '{SHA}', md5: '$apr1$', crypt: ''};


try{ if (algorithm == 'crypt') {
var c = crypto.createHash(algorithm);
c.update(password); exec('openssl passwd -crypt "' + password.replace(/"/,"\\\"") + '"', function(error, stdout, stderr) {
c = c.digest(digest); if (error) return callback && callback(E, null);
}catch(E){ return callback && callback(null, stdout.trim());
return callback && callback(E, null); });

} else {
try{
var c = crypto.createHash(algorithm);
c.update(password);
c = c.digest(digest);

}catch(E){
return callback && callback(E, null);
}
callback && callback(null, hash_prefix[algorithm] + c);
} }
callback && callback(null, hash_prefix[algorithm] + c);
} }


/** /**
Expand Down

0 comments on commit a20a282

Please sign in to comment.