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 3.0.0 to 3.0.1

dist/md5.js

68

dist/index.js

@@ -1,64 +0,10 @@

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;
}
import { verifyMD5 } from './md5.js';
import { verifySSHA } from './ssha.js';
import { verifySha512Crypt } from './sha512.js';
export function ldapVerifyAll(textPassword, hashedPassword) {
return verifyMD5(textPassword, hashedPassword) || verifySSHA(textPassword, hashedPassword) || verifySha512(textPassword, hashedPassword);
return verifyMD5(textPassword, hashedPassword) || verifySSHA(textPassword, hashedPassword) || verifySha512Crypt(textPassword, hashedPassword);
}
export { md5, verifyMD5 } from './md5.js';
export { ssha, verifySSHA } from './ssha.js';
export { sha512Crypt, verifySha512Crypt } from './sha512.js';
//# sourceMappingURL=index.js.map

@@ -0,0 +0,0 @@ import { defineConfig } from 'vitepress'

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

{ text: 'sha512Crypt', link: '/guide/sha512crypt' },
{ text: 'verifySha512', link: '/guide/verifysha512' },
{ text: 'verifySha512Crypt', link: '/guide/verifysha512crypt' },
],

@@ -25,0 +25,0 @@ },

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

{ text: 'sha512Crypt', link: '/pt/guide/sha512crypt' },
{ text: 'verifySha512', link: '/pt/guide/verifysha512' },
{ text: 'verifySha512Crypt', link: '/pt/guide/verifysha512crypt' },
],

@@ -55,0 +55,0 @@ },

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

@@ -0,0 +0,0 @@ # Getting Started

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

@@ -0,0 +0,0 @@ # md5

@@ -0,0 +0,0 @@ # sha512Crypt

@@ -0,0 +0,0 @@ # ssha

@@ -0,0 +0,0 @@ # verifyMD5

@@ -0,0 +0,0 @@ # verifySSHA

@@ -19,5 +19,5 @@ ---

features:
- title: ⚡️ SHA512
- title: ⚡️ SHA512 CRYPT
- title: 💡 SSHA
- title: 💥 MD5
---

@@ -0,0 +0,0 @@ # Começando

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

@@ -0,0 +0,0 @@ # md5

@@ -0,0 +0,0 @@ # sha512Crypt

@@ -0,0 +0,0 @@ # ssha

@@ -0,0 +0,0 @@ # verifyMD5

@@ -0,0 +0,0 @@ # verifySSHA

@@ -19,5 +19,5 @@ ---

features:
- title: ⚡️ SHA512
- title: ⚡️ SHA512 CRYPT
- title: 💡 SSHA
- title: 💥 MD5
---
{
"name": "ldap-passwords",
"type": "module",
"version": "3.0.0",
"version": "3.0.1",
"description": "ldap-passwords offers secure password hashing and verification using LDAP password algorithms.",

@@ -6,0 +6,0 @@ "author": {

@@ -49,3 +49,3 @@ <a href="http://ldap-passwords.com/">

```ts
import { sha512Crypt, verifySha512 } from 'ldap-passwords'
import { sha512Crypt, verifySha512Crypt } from 'ldap-passwords'
```

@@ -69,3 +69,3 @@

```ts
const isValid = verifySha512('mySuperSecretPassword', arrayOfSha512Passwords)
const isValid = verifySha512Crypt('mySuperSecretPassword', arrayOfSha512Passwords)
// return true or false

@@ -72,0 +72,0 @@ ```

@@ -1,95 +0,7 @@

/**
* @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 { sha512Crypt, verifySha512 } from './sha512'
export { ssha, verifySSHA } from './ssha'
export { md5, verifyMD5 } from './md5'
/**
* @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.

@@ -96,0 +8,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