Skip to content

Commit

Permalink
Describe your changes here
Browse files Browse the repository at this point in the history
  • Loading branch information
Ishratnoori committed Oct 28, 2024
1 parent 2dcd2e7 commit bde5756
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
const crypto = require('crypto');

// Function to encrypt password

function encryptPassword(password) {
const salt = crypto.randomBytes(16).toString('hex'); // Generate a salt
const iterations = 100000; // Number of iterations
const keylen = 64; // Length of the derived key
const digest = 'sha512'; // Hashing algorithm
const salt = crypto.randomBytes(16).toString('hex');
const iterations = 100000;
const keylen = 64;
const digest = 'sha512';

// Derive a key using PBKDF2

const hashedPassword = crypto.pbkdf2Sync(password, salt, iterations, keylen, digest).toString('hex');

return { salt, hashedPassword };
}

// Function to verify password

function verifyPassword(password, salt, hashedPassword) {
const keylen = 64;
const iterations = 100000;
const digest = 'sha512';
const derivedKey = crypto.pbkdf2Sync(password, salt, iterations, keylen, digest).toString('hex');

return derivedKey === hashedPassword; // Compare the derived key with the stored hashed password
}
return derivedKey === hashedPassword;

// Example usage
const password = 'yourPassword123'; // Replace with the password you want to encrypt
}
const password = 'yourPassword123';
const { salt, hashedPassword } = encryptPassword(password);
console.log(`Salt: ${salt}`);
console.log(`Encrypted Password: ${hashedPassword}`);
Expand Down

0 comments on commit bde5756

Please sign in to comment.