Skip to content

Commit

Permalink
Crypt dep is mandatory now.
Browse files Browse the repository at this point in the history
  • Loading branch information
gevorg committed Dec 15, 2014
1 parent 6acbe8b commit f6f5078
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 23 deletions.
1 change: 0 additions & 1 deletion lib/htpasswd.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ if (require.main === module ) {
} else { // Library mode.
utils = require('./utils');
module.exports.verify = utils.verify;
module.exports.isCryptInstalled = utils.isCryptInstalled;
}
5 changes: 1 addition & 4 deletions lib/program.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ program
.option('-c, --create', "Create a new file.")
.option('-n, --nofile', "Don't update file; display results on stdout.")
.option('-m, --md5', "Use MD5 encryption for passwords. This is the default.")

if utils.isCryptInstalled() # Only if crypt is installed.
program
.option('-d, --crypt', "Use crypt() encryption for passwords. This algorithm limits the password length to 8 characters. This algorithm is insecure by today's standards.")
.option('-d, --crypt', "Use crypt() encryption for passwords. This algorithm limits the password length to 8 characters. This algorithm is insecure by today's standards.")

program
.option('-s, --sha', "Use SHA encryption for passwords. This algorithm is insecure by today's standards.")
Expand Down
15 changes: 4 additions & 11 deletions lib/utils.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,15 @@ crypto = require 'crypto'
# Importing apache-md5 module.
md5 = require 'apache-md5'

# Importing apache-crypt module.
crypt = require 'apache-crypt'

# Module for utility functionalities.
module.exports =

# Check if crypt is available.
isCryptInstalled: () ->
try
not not require.resolve 'apache-crypt'
catch
false

# Crypt method.
crypt3: (password, hash) ->
if module.exports.isCryptInstalled()
(require 'apache-crypt')(password, hash)
else
console.warn "[apache-crypt] IS NOT INSTALLED!"
crypt password, hash

# Generates sha1 hash of password.
sha1: (password) ->
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "htpasswd",
"description": "Node.js package for HTTP Basic Authentication password file utility.",
"version": "2.1.5",
"version": "2.1.6",
"author": "Gevorg Harutyunyan (http://github.com/gevorg)",
"maintainers": [
{
Expand Down
9 changes: 3 additions & 6 deletions tests/test-utils.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ module.exports =

# Test for crypt3 option.
testEncodeCrypt3: (test) ->
if utils.isCryptInstalled()
encoded = utils.encode {'crypt': true, 'args': ["olga", "chexova111"]}
test.equal (utils.crypt3 "chexova111", encoded), encoded, "Password is wrong!"
encoded = utils.encode {'crypt': true, 'args': ["olga", "chexova111"]}
test.equal (utils.crypt3 "chexova111", encoded), encoded, "Password is wrong!"

test.done()

Expand Down Expand Up @@ -64,9 +63,7 @@ module.exports =

# Test for verify with correct crypt pass.
testVerifyCryptOk: (test) ->
if utils.isCryptInstalled()
test.ok utils.verify "hVmhA.naUQQ3I", "raya"

test.ok utils.verify "hVmhA.naUQQ3I", "raya"
test.done()

# Test for verify with wrong crypt pass.
Expand Down

0 comments on commit f6f5078

Please sign in to comment.