Skip to content

Commit

Permalink
Resolved merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Ishratnoori committed Nov 5, 2024
2 parents 2933a71 + bde5756 commit 2c365b3
Show file tree
Hide file tree
Showing 3 changed files with 685 additions and 1 deletion.
29 changes: 28 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,57 @@
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

// Derive a key using PBKDF2


function encryptPassword(password) {
const salt = crypto.randomBytes(16).toString('hex');
const iterations = 100000;
const keylen = 64;
const digest = 'sha512';



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
}

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

return derivedKey === hashedPassword;

}
const password = 'yourPassword123';
const { salt, hashedPassword } = encryptPassword(password);
console.log(`Salt: ${salt}`);
console.log(`Encrypted Password: ${hashedPassword}`);

const isMatch = verifyPassword(password, salt, hashedPassword);
console.log(`Password Match: ${isMatch}`);

Loading

0 comments on commit 2c365b3

Please sign in to comment.