New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

htpasswd-mgr

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

htpasswd-mgr - npm Package Compare versions

Comparing version 1.1.7 to 2.0.0-beta.0

lib/constants.d.ts

28

lib/crypto.js

@@ -1,23 +0,19 @@

const crypto = require('crypto'),
bcryptLib = require('bcrypt'),
SALT_ROUNDS = 5;
module.exports = {
sha1: sha1,
bcrypt: bcrypt
};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.bcrypt = exports.sha1 = void 0;
const crypto_1 = require("crypto");
const bcrypt_1 = require("bcrypt");
const SALT_ROUNDS = 5;
// Return a SHA1 representation of the value
function sha1(value) {
let hash = crypto.createHash('sha1');
const hash = (0, crypto_1.createHash)('sha1');
hash.update(value);
return hash.digest('base64');
}
exports.sha1 = sha1;
function bcrypt(value) {
let salt = bcryptLib.genSaltSync(SALT_ROUNDS);
return bcryptLib.hashSync(value, salt);
const salt = (0, bcrypt_1.genSaltSync)(SALT_ROUNDS);
return (0, bcrypt_1.hashSync)(value, salt);
}
exports.bcrypt = bcrypt;
//# sourceMappingURL=crypto.js.map
'use strict';
const { promisify } = require('bluebird'),
fs = require('fs'),
md5 = require('apache-md5'),
crypt = require('apache-crypt'),
writeFileAsync = promisify(fs.writeFile),
crypto = require('./crypto'),
constants = require('./constants');
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.HTPasswdAlgorithms = void 0;
const fs_1 = require("fs");
const apache_md5_1 = __importDefault(require("apache-md5"));
const apache_crypt_1 = __importDefault(require("apache-crypt"));
const crypto_1 = require("./crypto");
const constants_1 = require("./constants");
var HTPasswdAlgorithms;
(function (HTPasswdAlgorithms) {
HTPasswdAlgorithms["crypt"] = "crypt";
HTPasswdAlgorithms["sha"] = "sha";
HTPasswdAlgorithms["bcrypt"] = "bcrypt";
HTPasswdAlgorithms["md5"] = "md5";
})(HTPasswdAlgorithms = exports.HTPasswdAlgorithms || (exports.HTPasswdAlgorithms = {}));
const defaultOptions = {
export: true,
algorithm: HTPasswdAlgorithms.md5,
};
function initialize(path) {
let htpasswd = {};
const exports = {
updateState: readFile,
updateFile: exportToFile,
addUser: addUser,
updateUser: updateUser,
upsertUser: addOrUpdateUser,
removeUser: removeUser,
listUsers: listUsers
};
function readFile() {
if (fs.existsSync(path)) {
let htpasswdContents = fs.readFileSync(path, {encoding: 'utf8'});
const htpasswd = {};
async function readFile() {
if ((0, fs_1.existsSync)(path)) {
const htpasswdContents = (0, fs_1.readFileSync)(path, { encoding: 'utf8' });
parseFile(htpasswdContents);
}
return Promise.resolve();
return;
}
function parseFile(fileContents) {
let lines = fileContents.trim().split('\n');
for (let line of lines) {
let [username, password] = line.split(':');
htpasswd[username] = [password];
const lines = fileContents.trim().split('\n');
for (const line of lines) {
const splitLine = line.split(':');
const [username, password] = splitLine;
htpasswd[username] = password;
}
}
function exportToFile() {
return convertHTPasswdToString()
.then(writeFile);
.then(writeToFile);
}
function writeFile(data) {
return writeFileAsync(path, data, {encoding: 'utf8'});
function writeToFile(data) {
return new Promise((resolve, reject) => {
(0, fs_1.writeFile)(path, data, { encoding: 'utf8' }, (err) => {
if (err)
reject(err);
else
resolve(true);
});
});
}
function convertHTPasswdToString() {
async function convertHTPasswdToString() {
let accumulator = '';
for (let username in htpasswd) {
let password = htpasswd[username],
userInfo = username + ':' + password + '\n';
for (const username in htpasswd) {
const password = htpasswd[username], userInfo = username + ':' + password + '\n';
accumulator += userInfo;
}
return Promise.resolve(accumulator);
return accumulator;
}
function encodePassword(password, algorithm) {
switch (algorithm) {
switch (algorithm?.toLowerCase()) {
case 'crypt':
return crypt(password);
return (0, apache_crypt_1.default)(password);
case 'sha':
return crypto.sha1(password);
return (0, crypto_1.sha1)(password);
case 'bcrypt':
return crypto.bcrypt(password);
return (0, crypto_1.bcrypt)(password);
case 'md5':
default:
return md5(password);
return (0, apache_md5_1.default)(password);
}
}
function optionalExport(exportOption) {
async function optionalExport(exportOption) {
switch (exportOption) {
case false:
return Promise.resolve();
return;
default:

@@ -84,51 +83,43 @@ return exportToFile();

}
/**
* Add a user to the htpasswd file and optionally export it to disk
* @param username {String} name of user to be added
* @param password {String} password for the user to be added
* @param options {Object} object with options - example { algorithm: 'crypt', export: false }
*/
function addUser(username, password, options) {
async function addUser(username, password, options) {
if (htpasswd[username]) {
return Promise.reject(new Error(constants.errors.usernameAlreadyInUse));
throw new Error(constants_1.errors.usernameAlreadyInUse);
}
return addOrUpdateUser(username, password, options);
}
function updateUser(username, password, options) {
async function updateUser(username, password, options) {
if (!htpasswd[username]) {
return Promise.reject(new Error(constants.errors.noSuchUser));
throw new Error(constants_1.errors.noSuchUser);
}
return addOrUpdateUser(username, password, options);
}
function addOrUpdateUser(username, password, options) {
const algorithm = options && options.algorithm && options.algorithm.toLowerCase(),
exportOption = options && options.export;
const algorithm = options?.algorithm ?? defaultOptions.algorithm, exportOption = options?.export ?? defaultOptions.export;
htpasswd[username] = encodePassword(password, algorithm);
return optionalExport(exportOption);
}
function removeUser(username, options) {
const exportOption = options && options.export;
const exportOption = options?.export ?? defaultOptions.export;
delete htpasswd[username];
return optionalExport(exportOption);
}
function listUsers() {
return Promise.resolve(Object.keys(htpasswd));
async function listUsers() {
return Object.keys(htpasswd);
}
// Update the internal state of the module
readFile();
return exports;
return {
updateState: readFile,
updateFile: exportToFile,
addUser,
updateUser,
upsertUser: addOrUpdateUser,
removeUser,
listUsers,
};
}
module.exports = initialize;
exports.default = initialize;
//# sourceMappingURL=manager.js.map

@@ -5,3 +5,3 @@ {

"description": "HTPasswd Manager for Node.js",
"version": "1.1.7",
"version": "2.0.0-beta.0",
"homepage": "https://mrodrig.github.io/htpasswd-mgr",

@@ -13,7 +13,10 @@ "repository": {

"main": "lib/manager.js",
"types": "./lib/manager.d.ts",
"scripts": {
"test": "./node_modules/.bin/mocha test/tests.js",
"coverage": "nyc --reporter=lcov --reporter=text-summary --reporter=text _mocha",
"coveralls": "nyc report --reporter=text-lcov | coveralls",
"lint": "./node_modules/.bin/eslint lib test"
"build": "npm run lint && npm run test && npm run compile",
"compile": "tsc -p tsconfig.build.json",
"coverage": "nyc npm run test",
"lint": "eslint --ext .js,.ts src test",
"prepublishOnly": "npm run build",
"test": "mocha -r ts-node/register test/index.ts"
},

@@ -28,4 +31,4 @@ "keywords": [

"dependencies": {
"apache-crypt": "1.2.5",
"apache-md5": "1.1.7",
"apache-crypt": "1.2.6",
"apache-md5": "1.1.8",
"bcrypt": "5.0.1",

@@ -35,12 +38,20 @@ "bluebird": "3.7.2"

"devDependencies": {
"coveralls": "3.1.1",
"eslint": "8.7.0",
"mocha": "9.2.0",
"@types/bcrypt": "5.0.0",
"@types/mocha": "10.0.1",
"@types/node": "18.15.3",
"@typescript-eslint/eslint-plugin": "5.55.0",
"@typescript-eslint/parser": "5.55.0",
"eslint": "8.36.0",
"eslint-config-google": "0.14.0",
"eslint-plugin-import": "2.27.5",
"mocha": "10.2.0",
"nyc": "15.1.0",
"ts-node": "10.9.1",
"typescript": "5.0.2",
"should": "13.2.3"
},
"engines": {
"node": ">= 12"
"node": ">= 16"
},
"license": "MIT"
}
# htpasswd-mgr - The HTPasswd Manager for Node
[![Dependencies](https://img.shields.io/david/mrodrig/htpasswd-mgr.svg?style=flat-square)](https://www.npmjs.org/package/htpasswd-mgr)
[![Downloads](http://img.shields.io/npm/dm/htpasswd-mgr.svg)](https://www.npmjs.org/package/htpasswd-mgr)
[![NPM version](https://img.shields.io/npm/v/htpasswd-mgr.svg)](https://www.npmjs.org/package/htpasswd-mgr)
[![Minzipped Size](https://flat.badgen.net/bundlephobia/minzip/htpasswd-mgr)](https://bundlephobia.com/result?p=htpasswd-mgr)
[![Typings](https://img.shields.io/npm/types/htpasswd-mgr)](https://www.npmjs.org/package/htpasswd-mgr)
[![Downloads](https://img.shields.io/npm/dm/htpasswd-mgr.svg)](https://www.npmjs.org/package/htpasswd-mgr)
[![Minzipped Size](https://img.shields.io/bundlephobia/minzip/htpasswd-mgr)](https://bundlephobia.com/result?p=htpasswd-mgr)
[![Build Status](https://travis-ci.org/mrodrig/htpasswd-mgr.svg?branch=master)](https://travis-ci.org/mrodrig/htpasswd-mgr)
[![Coverage Status](https://coveralls.io/repos/github/mrodrig/htpasswd-mgr/badge.svg?branch=stable)](https://coveralls.io/github/mrodrig/htpasswd-mgr?branch=stable)
[![Maintainability](https://api.codeclimate.com/v1/badges/41cf01fb45ce64976122/maintainability)](https://codeclimate.com/github/mrodrig/htpasswd-mgr/maintainability)
[![Build Status](https://img.shields.io/github/actions/workflow/status/mrodrig/htpasswd-mgr/automated-tests-workflow.yml)](https://github.com/mrodrig/htpasswd-mgr/actions/workflows/automated-tests-workflow.yml)
[![Coverage Status](https://coveralls.io/repos/github/mrodrig/htpasswd-mgr/badge.svg?branch=stable)](https://coveralls.io/github/mrodrig/htpasswd-mgr?branch=main)
[![Maintainability](https://api.codeclimate.com/v1/badges/8c0cc3699d054fb77abe/maintainability)](https://codeclimate.com/github/mrodrig/htpasswd-mgr/maintainability)

@@ -12,0 +12,0 @@ This module was developed to simplify the management of .htpasswd files from

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc