Permalink
Browse files

Merge pull request #4 from rgeber/master

Added CRYPT support to hash generator
  • Loading branch information...
andris9 committed Mar 20, 2013
2 parents da9114b + ff18c38 commit a20a2824d7ff99aad311126607c6302bb3bfbdf5
Showing with 25 additions and 11 deletions.
  1. +7 −3 package.json
  2. +18 −8 pass.js
View
@@ -1,15 +1,19 @@
-{
+{
"name" : "pass",
- "version": "0.1.1",
+ "version": "0.1.2",
"main" : "./index",
"description": "Apache htpasswd password generator/validator",
"author" : "Andris Reinman",
"maintainers":[
{
"name":"andris",
"email":"andris@node.ee"
+ },
+ {
+ "name":"rgeber",
+ "email":"geber@b1-systems.de"
}
- ],
+ ],
"repository" : {
"type" : "git",
"url" : "http://github.com/andris9/pass"
View
26 pass.js
@@ -15,16 +15,26 @@ exports.generate = function(password, callback, param){
var algorithm = param.algorithm ? param.algorithm : 'sha1';
var digest = param.digest ? param.digest : 'base64';
- var hash_prefix = {sha1: '{SHA}', md5: '$apr1$'};
+ var hash_prefix = {sha1: '{SHA}', md5: '$apr1$', crypt: ''};
- try{
- var c = crypto.createHash(algorithm);
- c.update(password);
- c = c.digest(digest);
- }catch(E){
- return callback && callback(E, null);
+ if (algorithm == 'crypt') {
+
+ exec('openssl passwd -crypt "' + password.replace(/"/,"\\\"") + '"', function(error, stdout, stderr) {
+ if (error) return callback && callback(E, null);
+ return callback && callback(null, stdout.trim());
+ });
+
+ } 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);
}
/**

0 comments on commit a20a282

Please sign in to comment.