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

ldap-passwords

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ldap-passwords - npm Package Compare versions

Comparing version 2.1.3 to 3.0.0

dist/md5Helpers.js

64

dist/index.js

@@ -1,5 +0,61 @@

import { md5, verifyMD5 } from 'ldap-md5';
import { ssha, verifySSHA } from 'ldap-sha';
import { sha512Crypt, verifySha512 } from 'ldap-sha512';
export { md5, verifyMD5, ssha, verifySSHA, sha512Crypt, verifySha512 };
import { Buffer } from 'node:buffer';
import { randomBytes } from 'node:crypto';
import md5Helper from './md5Helpers.js';
import sshaHelpers from './sshaHelpers.js';
import sha512Helpers from './sha512Helpers.js';
export function md5(textPassword) {
return md5Helper(textPassword);
}
export function verifyMD5(textPassword, md5Password) {
let isValid = false;
const md5Passwords = typeof md5Password === 'string' ? [md5Password] : md5Password;
for (const cryptPasswd of md5Passwords) {
const hashType = cryptPasswd.match(/\{([^}]+)\}/);
if (hashType && hashType[1] === 'MD5') {
const hashedPassword = md5(textPassword);
if (hashedPassword === cryptPasswd)
isValid = true;
}
}
return isValid;
}
export function ssha(textPassword) {
return sshaHelpers(textPassword);
}
export function verifySSHA(textPassword, sshaPassword) {
let isValid = false;
const sshaPasswords = typeof sshaPassword === 'string' ? [sshaPassword] : sshaPassword;
for (const cryptPasswd of sshaPasswords) {
const hashType = cryptPasswd.match(/\{([^}]+)\}/);
if (hashType && hashType[1] === 'SSHA') {
const buffer = Buffer.from(cryptPasswd.slice(6), 'base64');
const salt = Uint8Array.prototype.slice.call(buffer, 20);
const hashedPassword = sshaHelpers(textPassword, salt);
if (hashedPassword === cryptPasswd)
isValid = true;
}
}
return isValid;
}
export function sha512Crypt(textPassword, salt = '') {
if (!salt)
salt = randomBytes(16).toString('base64').substring(0, 16);
if (salt.length > 16)
throw new Error('The maximum length of salt is 16 characters');
return sha512Helpers(textPassword, salt);
}
export function verifySha512(textPassword, sha512Password) {
let isValid = false;
const sha512Passwords = typeof sha512Password === 'string' ? [sha512Password] : sha512Password;
for (const cryptPasswd of sha512Passwords) {
const hashType = cryptPasswd.match(/\{([^}]+)\}/);
if (hashType && hashType[1] === 'CRYPT') {
const salt = cryptPasswd.split('$')[2];
const hashedPassword = sha512Crypt(textPassword, salt);
if (hashedPassword === cryptPasswd)
isValid = true;
}
}
return isValid;
}
export function ldapVerifyAll(textPassword, hashedPassword) {

@@ -6,0 +62,0 @@ return verifyMD5(textPassword, hashedPassword) || verifySSHA(textPassword, hashedPassword) || verifySha512(textPassword, hashedPassword);

3

docs/.vitepress/config/index.ts

@@ -25,3 +25,4 @@ import { defineConfig } from 'vitepress'

{ icon: 'github', link: 'https://github.com/dethdkn/ldap-passwords' },
{ icon: { svg: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="currentColor" d="M16.36 14c.08-.66.14-1.32.14-2c0-.68-.06-1.34-.14-2h3.38c.16.64.26 1.31.26 2s-.1 1.36-.26 2m-5.15 5.56c.6-1.11 1.06-2.31 1.38-3.56h2.95a8.03 8.03 0 0 1-4.33 3.56M14.34 14H9.66c-.1-.66-.16-1.32-.16-2c0-.68.06-1.35.16-2h4.68c.09.65.16 1.32.16 2c0 .68-.07 1.34-.16 2M12 19.96c-.83-1.2-1.5-2.53-1.91-3.96h3.82c-.41 1.43-1.08 2.76-1.91 3.96M8 8H5.08A7.923 7.923 0 0 1 9.4 4.44C8.8 5.55 8.35 6.75 8 8m-2.92 8H8c.35 1.25.8 2.45 1.4 3.56A8.008 8.008 0 0 1 5.08 16m-.82-2C4.1 13.36 4 12.69 4 12s.1-1.36.26-2h3.38c-.08.66-.14 1.32-.14 2c0 .68.06 1.34.14 2M12 4.03c.83 1.2 1.5 2.54 1.91 3.97h-3.82c.41-1.43 1.08-2.77 1.91-3.97M18.92 8h-2.95a15.65 15.65 0 0 0-1.38-3.56c1.84.63 3.37 1.9 4.33 3.56M12 2C6.47 2 2 6.5 2 12a10 10 0 0 0 10 10a10 10 0 0 0 10-10A10 10 0 0 0 12 2"/></svg>' }, link: 'https://rosa.dev.br' },
{ icon: { svg: '<svg xmlns="http://www.w3.org/2000/svg" width="1.13em" height="1em" viewBox="0 0 576 512"><path fill="currentColor" d="M288 288h-32v-64h32zm288-128v192H288v32H160v-32H0V160zm-416 32H32v128h64v-96h32v96h32zm160 0H192v160h64v-32h64zm224 0H352v128h64v-96h32v96h32v-96h32v96h32z"/></svg>' }, link: 'https://www.npmjs.com/package/ldap-passwords', ariaLabel: 'npm' },
{ icon: { svg: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="currentColor" d="M16.36 14c.08-.66.14-1.32.14-2c0-.68-.06-1.34-.14-2h3.38c.16.64.26 1.31.26 2s-.1 1.36-.26 2m-5.15 5.56c.6-1.11 1.06-2.31 1.38-3.56h2.95a8.03 8.03 0 0 1-4.33 3.56M14.34 14H9.66c-.1-.66-.16-1.32-.16-2c0-.68.06-1.35.16-2h4.68c.09.65.16 1.32.16 2c0 .68-.07 1.34-.16 2M12 19.96c-.83-1.2-1.5-2.53-1.91-3.96h3.82c-.41 1.43-1.08 2.76-1.91 3.96M8 8H5.08A7.923 7.923 0 0 1 9.4 4.44C8.8 5.55 8.35 6.75 8 8m-2.92 8H8c.35 1.25.8 2.45 1.4 3.56A8.008 8.008 0 0 1 5.08 16m-.82-2C4.1 13.36 4 12.69 4 12s.1-1.36.26-2h3.38c-.08.66-.14 1.32-.14 2c0 .68.06 1.34.14 2M12 4.03c.83 1.2 1.5 2.54 1.91 3.97h-3.82c.41-1.43 1.08-2.77 1.91-3.97M18.92 8h-2.95a15.65 15.65 0 0 0-1.38-3.56c1.84.63 3.37 1.9 4.33 3.56M12 2C6.47 2 2 6.5 2 12a10 10 0 0 0 10 10a10 10 0 0 0 10-10A10 10 0 0 0 12 2"/></svg>' }, link: 'https://rosa.dev.br', ariaLabel: 'Me ;)' },
],

@@ -28,0 +29,0 @@ },

@@ -23,4 +23,2 @@ import { defineConfig } from 'vitepress'

{ text: 'verifySha512', link: '/guide/verifysha512' },
{ text: 'Sha512 Online Generator', link: '/online/sha512crypt' },
{ text: 'Sha512 Online Validator', link: '/online/verifysha512' },
],

@@ -33,4 +31,2 @@ },

{ text: 'verifySSHA', link: '/guide/verifyssha' },
{ text: 'SSHA Online Generator', link: '/online/ssha' },
{ text: 'SSHA Online Validator', link: '/online/verifyssha' },
],

@@ -43,4 +39,2 @@ },

{ text: 'verifyMD5', link: '/guide/verifymd5' },
{ text: 'MD5 Online Generator', link: '/online/md5' },
{ text: 'MD5 Online Validator', link: '/online/verifymd5' },
],

@@ -47,0 +41,0 @@ },

@@ -53,4 +53,2 @@ import { defineConfig } from 'vitepress'

{ text: 'verifySha512', link: '/pt/guide/verifysha512' },
{ text: 'Sha512 Gerador Online', link: '/pt/online/sha512crypt' },
{ text: 'Sha512 Validador Online', link: '/pt/online/verifysha512' },
],

@@ -63,4 +61,2 @@ },

{ text: 'verifySSHA', link: '/pt/guide/verifyssha' },
{ text: 'SSHA Gerador Online', link: '/pt/online/ssha' },
{ text: 'SSHA Validador Online', link: '/pt/online/verifyssha' },
],

@@ -73,4 +69,2 @@ },

{ text: 'verifyMD5', link: '/pt/guide/verifymd5' },
{ text: 'MD5 Gerador Online', link: '/pt/online/md5' },
{ text: 'MD5 Validador Online', link: '/pt/online/verifymd5' },
],

@@ -77,0 +71,0 @@ },

@@ -0,0 +0,0 @@ import theme from 'vitepress/theme'

# Getting Started
**Welcome to the documentation for the ldap-passwords package, a collection of tools for generating LDAP password hashes using various algorithms. This package includes three sub-packages: ldap-md5, ldap-sha and ldap-sha512. You have the flexibility to either install the combined package or choose specific algorithms based on your requirements.**
**Welcome to the documentation for the ldap-passwords package, a collection of tools for generating LDAP password hashes using various algorithms.**
## Option 1: Install ldap-passwords (Includes everything)
## Installation

@@ -12,24 +12,1 @@ Install with your favorite package manager:

- bun : `bun add ldap-passwords`
## Option 2: Install individual packages
### SHA512
Install with your favorite package manager:
- **pnpm** : `pnpm i ldap-sha512`
- npm : `npm i ldap-sha512`
- yarn : `yarn add ldap-sha512`
- bun : `bun add ldap-sha512`
### SSHA
Install with your favorite package manager:
- **pnpm** : `pnpm i ldap-sha`
- npm : `npm i ldap-sha`
- yarn : `yarn add ldap-sha`
- bun : `bun add ldap-sha`
### MD5
Install with your favorite package manager:
- **pnpm** : `pnpm i ldap-md5`
- npm : `npm i ldap-md5`
- yarn : `yarn add ldap-md5`
- bun : `bun add ldap-md5`

@@ -0,0 +0,0 @@ # ldapVerifyAll

@@ -10,4 +10,2 @@ # md5

import { md5 } from 'ldap-passwords'
// OR
import { md5 } from 'ldap-md5'
```

@@ -14,0 +12,0 @@

@@ -6,4 +6,2 @@ # sha512Crypt

import { sha512Crypt } from 'ldap-passwords'
// OR
import { sha512Crypt } from 'ldap-sha512'
```

@@ -10,0 +8,0 @@

@@ -6,4 +6,2 @@ # ssha

import { ssha } from 'ldap-passwords'
// OR
import { ssha } from 'ldap-sha'
```

@@ -10,0 +8,0 @@

@@ -10,4 +10,2 @@ # verifyMD5

import { verifyMD5 } from 'ldap-passwords'
// OR
import { verifyMD5 } from 'ldap-md5'
```

@@ -14,0 +12,0 @@

@@ -6,4 +6,2 @@ # verifySha512

import { verifySha512 } from 'ldap-passwords'
// OR
import { verifySha512 } from 'ldap-sha512'
```

@@ -10,0 +8,0 @@

@@ -6,4 +6,2 @@ # verifySSHA

import { verifySSHA } from 'ldap-passwords'
// OR
import { verifySSHA } from 'ldap-sha'
```

@@ -10,0 +8,0 @@

@@ -0,0 +0,0 @@ ---

# Começando
**Bem-vindo à documentação do pacote ldap-passwords, uma coleção de ferramentas para gerar hashes de senhas LDAP usando vários algoritmos. Este pacote inclui três subpacotes: ldap-md5, ldap-sha e ldap-sha512. Você tem a flexibilidade de instalar o pacote combinado ou escolher algoritmos específicos com base em seus requisitos.**
**Bem-vindo à documentação do pacote ldap-passwords, uma coleção de ferramentas para gerar hashes de senhas LDAP usando vários algoritmos.**
## Opção 1: Instale ldap-passwords (Inclui tudo)
## Instalação

@@ -12,24 +12,1 @@ Instale com seu gerenciador de pacotes favorito:

- bun : `bun add ldap-passwords`
## Opção 2: Instale pacotes individuais
### SHA512
Instale com seu gerenciador de pacotes favorito:
- **pnpm** : `pnpm i ldap-sha512`
- npm : `npm i ldap-sha512`
- yarn : `yarn add ldap-sha512`
- bun : `bun add ldap-sha512`
### SSHA
Instale com seu gerenciador de pacotes favorito:
- **pnpm** : `pnpm i ldap-sha`
- npm : `npm i ldap-sha`
- yarn : `yarn add ldap-sha`
- bun : `bun add ldap-sha`
### MD5
Instale com seu gerenciador de pacotes favorito:
- **pnpm** : `pnpm i ldap-md5`
- npm : `npm i ldap-md5`
- yarn : `yarn add ldap-md5`
- bun : `bun add ldap-md5`

@@ -0,0 +0,0 @@ # ldapVerifyAll

@@ -10,4 +10,2 @@ # md5

import { md5 } from 'ldap-passwords'
// OR
import { md5 } from 'ldap-md5'
```

@@ -14,0 +12,0 @@

@@ -6,4 +6,2 @@ # sha512Crypt

import { sha512Crypt } from 'ldap-passwords'
// OR
import { sha512Crypt } from 'ldap-sha512'
```

@@ -10,0 +8,0 @@

@@ -6,4 +6,2 @@ # ssha

import { ssha } from 'ldap-passwords'
// OR
import { ssha } from 'ldap-sha'
```

@@ -10,0 +8,0 @@

@@ -10,4 +10,2 @@ # verifyMD5

import { verifyMD5 } from 'ldap-passwords'
// OR
import { verifyMD5 } from 'ldap-md5'
```

@@ -14,0 +12,0 @@

@@ -6,4 +6,2 @@ # verifySha512

import { verifySha512 } from 'ldap-passwords'
// OR
import { verifySha512 } from 'ldap-sha512'
```

@@ -10,0 +8,0 @@

@@ -6,4 +6,2 @@ # verifySSHA

import { verifySSHA } from 'ldap-passwords'
// OR
import { verifySSHA } from 'ldap-sha'
```

@@ -10,0 +8,0 @@

@@ -0,0 +0,0 @@ ---

{
"name": "ldap-passwords",
"type": "module",
"version": "2.1.3",
"version": "3.0.0",
"description": "ldap-passwords offers secure password hashing and verification using LDAP password algorithms.",

@@ -35,16 +35,11 @@ "author": {

},
"dependencies": {
"ldap-md5": "^1.0.2",
"ldap-sha": "^1.0.0",
"ldap-sha512": "^2.1.2"
},
"devDependencies": {
"@antfu/eslint-config": "^2.6.3",
"@types/node": "^20.11.6",
"@vercel/analytics": "^1.1.2",
"eslint": "^8.56.0",
"typescript": "^5.3.3",
"vitepress": "1.0.0-rc.40",
"vitest": "^1.2.1"
"@antfu/eslint-config": "^2.13.3",
"@types/node": "^20.12.7",
"@vercel/analytics": "^1.2.2",
"eslint": "8.57.0",
"typescript": "^5.4.5",
"vitepress": "1.1.0",
"vitest": "^1.5.0"
}
}

@@ -19,2 +19,7 @@ <a href="http://ldap-passwords.com/">

</p>
<h3 align="center">
<a href="https://ldap-passwords.com/">
📚 Full Documentation
</a>
</h3>

@@ -21,0 +26,0 @@ ## ✨ Features

@@ -1,9 +0,95 @@

import { md5, verifyMD5 } from 'ldap-md5/types/index'
import { ssha, verifySSHA } from 'ldap-sha/types/index'
import { sha512Crypt, verifySha512 } from 'ldap-sha512/types/index'
/**
* @function
* Encrypt a plain text password with the Ldap MD5 algorithm.
* Keep in mind that MD5 is not considered a secure hashing algorithm for storing passwords, as it is vulnerable to various attacks.
*
* @param {string} textPassword - Plain text password.
* @returns {string} - Encrypted password with the Ldap MD5 algorithm.
*
*
* @example
* const encryptedPassword = md5('mySuperSecretPassword')
* // return {MD5}aTVgaG9NWR2N1eNABkQgYQ==
*
*/
export declare function md5(textPassword: string): string
export { md5, verifyMD5, ssha, verifySSHA, sha512Crypt, verifySha512 }
/**
* @function
* Verify passwords encrypted with MD5.
* Keep in mind that MD5 is not considered a secure hashing algorithm for storing passwords, as it is vulnerable to various attacks.
*
* @param {string} textPassword - Plain text password.
* @param {string | string[]} md5Password - String or Array of strings to be compared to the plain text password.
*
* @example
* const isValid = verifyMD5('mySuperSecretPassword', arrayOfMD5Passwords)
* // return true or false
*/
export declare function verifyMD5(textPassword: string, md5Password: string | string[]): boolean
/**
* @function
* Encrypt a plain text password with the Ldap SSHA algorithm.
*
* @param {string} textPassword - Plain text password.
* @returns {string} - Encrypted password with the Ldap SSHA algorithm.
*
*
* @example
* const encryptedPassword = ssha('mySuperSecretPassword')
* // return {SSHA}sTIysPunEI4boe6OwgQO+/tRZao2OWJIbDMvY0g2UlM=
*
*/
export declare function ssha(textPassword: string): string
/**
* @function
* Verify passwords encrypted with SSHA.
*
* @param {string} textPassword - Plain text password.
* @param {string | string[]} sshaPassword - String or Array of strings to be compared to the plain text password.
*
* @example
* const isValid = verifySSHA('mySuperSecretPassword', arrayOfSSHAPasswords)
* // return true or false
*/
export declare function verifySSHA(textPassword: string, sshaPassword: string | string[]): boolean
/**
* @function
* Encrypt a plain text password with the Ldap sha512crypt algorithm.
*
* @param {string} textPassword - Plain text password.
* @param {string} salt - Salt used to hash the password (it can't be greater than 16 characters).
* @returns {string} - Encrypted password with the Ldap sha512crypt algorithm.
*
* @throws {Error} If salt length is greater than 16.
*
* @example
* const encryptedPassword = sha512Crypt('mySuperSecretPassword')
* // return {CRYPT}$6$NQgPVC0up/oNVCb4$Aduz92Zfo/PFDE/XhvA3QmSqHquqdNiCdZvc9N5/UTpEUepMdd/6Mq/TeoM07wvyxHpg8ELGVzTWZt2e7Z9LY/
*
* // OR
*
* const encryptedPassword = sha512Crypt('mySuperSecretPassword', 'myDopeCustomSalt')
* // return {CRYPT}$6$myDopeCustomSalt$4ENRn.vwcs09z0fjr6Jt3NMOFVkn.p9v7ilDcK/CwRnQm48Y5HawkiGivh4gBTLwSY4SQNfCAe05E1nCTpZ0u.
*/
export declare function sha512Crypt(textPassword: string, salt?: string): string
/**
* @function
* Verify passwords encrypted with sha512.
*
* @param {string} textPassword - Plain text password.
* @param {string | string[]} sha512Password - String or Array of strings to be compared to the plain text password.
*
* @example
* const isValid = verifySha512('mySuperSecretPassword', arrayOfSha512Passwords)
* // return true or false
*/
export declare function verifySha512(textPassword: string, sha512Password: string | string[]): boolean
/**
* @function
* Verify passwords encrypted with MD5, SSHA or SHA512 CRYPT.

@@ -10,0 +96,0 @@ *

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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