Skip to content

Commit

Permalink
fix fallback for crypt3
Browse files Browse the repository at this point in the history
  • Loading branch information
rlidwka committed Sep 17, 2014
1 parent 06e56fd commit 7cf9d6f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ try {
// optional, won't be available on windows
var crypt3 = require('crypt3')
} catch(err) {
crypt3 = function() {
return NaN
}
}

try {
Expand Down Expand Up @@ -79,8 +76,10 @@ function verify_password(user, passwd, hash) {
return passwd === hash.substr(7)
} else if (hash.indexOf('{SHA}') === 0) {
return crypto.createHash('sha1').update(passwd, 'binary').digest('base64') === hash.substr(5)
} else {
} else if (crypt3) {
return crypt3(passwd, hash) === hash
} else {
return false
}
}

Expand All @@ -91,8 +90,9 @@ function add_user_to_htpasswd(body, user, passwd) {
throw err
}

passwd = crypt3(passwd)
if (!passwd) {
if (crypt3) {
passwd = crypt3(passwd)
} else {
passwd = '{SHA}' + crypto.createHash('sha1').update(passwd, 'binary').digest('base64')
}
var comment = 'autocreated ' + (new Date()).toJSON()
Expand Down

0 comments on commit 7cf9d6f

Please sign in to comment.