<commit_before>/* global require console Buffer*/

var crypto = require('crypto');

function ssha_pass(passwd, salt, next) {
    function _ssha (passwd,salt,next ){
        var ctx = crypto.createHash('sha1');
        ctx.update(passwd);
        ctx.update(salt);
        var digest = ctx.digest();
        var ssha = '{SSHA}' + new Buffer(digest+salt,'binary').toString('base64');
        return next(null, ssha);
    }
    if(next === undefined) {
            next = salt;
            salt = null;
    }
    if(salt === null ){
        crypto.randomBytes(32, function(ex, buf) {
            if (ex) return next(ex);
            _ssha(passwd,buf.toString('base64') ,next);
            return null;
        });
    }else{
        _ssha(passwd,salt,next);
    }
    return null;
}

function checkssha(passwd, hash, next) {
    if (hash.substr(0,6) != '{SSHA}') {
        return false;
    }
    var bhash = new Buffer(hash.substr(6),'base64');
    var salt = bhash.toString('binary',20); // sha1 digests are 20 bytes long
    ssha_pass(passwd,salt,function(err,newssha){
        if(err) return next(err)
        return next(null,hash === newssha)
    });
    return null;
}

exports.checkssha = checkssha;<commit_msg>fixed exit callback when not {SSHA} password<commit_after>/* global require console Buffer*/

var crypto = require('crypto');

function ssha_pass(passwd, salt, next) {
    function _ssha (passwd,salt,next ){
        var ctx = crypto.createHash('sha1');
        ctx.update(passwd);
        ctx.update(salt);
        var digest = ctx.digest();
        var ssha = '{SSHA}' + new Buffer(digest+salt,'binary').toString('base64');
        return next(null, ssha);
    }
    if(next === undefined) {
            next = salt;
            salt = null;
    }
    if(salt === null ){
        crypto.randomBytes(32, function(ex, buf) {
            if (ex) return next(ex);
            _ssha(passwd,buf.toString('base64') ,next);
            return null;
        });
    }else{
        _ssha(passwd,salt,next);
    }
    return null;
}

function checkssha(passwd, hash, next) {
    if (hash.substr(0,6) != '{SSHA}') {
        return next(new Error('not {SSHA}'),false);
    }
    var bhash = new Buffer(hash.substr(6),'base64');
    var salt = bhash.toString('binary',20); // sha1 digests are 20 bytes long
    ssha_pass(passwd,salt,function(err,newssha){
        if(err) return next(err)
        return next(null,hash === newssha)
    });
    return null;
}

exports.checkssha = checkssha;
{'fraction_non_alphanumeric': 0.15202567188126756, 'fraction_numerical': 0.01363818692338548, 'mean_word_length': 2.507735583684951, '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': '5467991', 'n_tokens_mistral': 831, 'n_tokens_neox': 801, 'n_words': 181}