<commit_before>const crypto = require('crypto');

function readyToSave(user) {
    let res = {
        email: user.email,
        name: user.name,
        created: Date.now(),
        token: Date.now()
    };
    res.salt = crypto.randomBytes(128).toString('base64');
    res.passwordHash = crypto.pbkdf2Sync(user.password, res.salt, 1, 128, 'sha1').toString('hex');
    return res;
}

function comparePasswords(user, password) {
    if(!user.passwordHash || !password) return false;
    return crypto.pbkdf2Sync(password, user.salt, 1, 128, 'sha1').toString('hex') === user.passwordHash;
}

module.exports = {
    readyToSave,
    comparePasswords
};<commit_msg>generateHash<commit_after>const crypto = require('crypto');

function readyToSave(user) {
    let res = {
        email: user.email,
        name: user.name,
        created: Date.now(),
    };
    res.salt = crypto.randomBytes(128).toString('base64');
    res.passwordHash = generateHash(user.password, res.salt);
    return res;
}

function comparePasswords(user, password) {
    if(!user.passwordHash || !password) return false;
    return generateHash(password, user.salt) === user.passwordHash;
}

function generateHash(password, salt) {
    return crypto.pbkdf2Sync(password, salt, 1, 128, 'sha1').toString('hex');
  }

module.exports = {
    readyToSave,
    comparePasswords
};
{'fraction_non_alphanumeric': 0.14688427299703263, 'fraction_numerical': 0.020771513353115726, 'mean_word_length': 3.6517241379310343, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6842505', 'n_tokens_mistral': 445, 'n_tokens_neox': 420, 'n_words': 85}