core/server/data/validation/index.js
function characterOccurance(stringToTest) {
    var chars = {},
        allowedOccurancy,
        valid = true;

    stringToTest = _.toString(stringToTest);
    allowedOccurancy = stringToTest.length / 2;

    // Loop through string and accumulate character counts
    _.each(stringToTest, function (char) {
        if (!chars[char]) {
            chars[char] = 1;
        } else {
            chars[char] += 1;
        }
    });

    // check if any of the accumulated chars exceed the allowed occurancy
    // of 50% of the words' length.
    _.forIn(chars, function (charCount) {
        if (charCount >= allowedOccurancy) {
            valid = false;
        }
    });

    return valid;
}
function characterOccurance(stringToTest) {
    var chars = {},
        allowedOccurancy,
        valid = true;

    stringToTest = _.toString(stringToTest);
    allowedOccurancy = stringToTest.length / 2;

    // Loop through string and accumulate character counts
    _.each(stringToTest, function (char) {
        if (!chars[char]) {
            chars[char] = 1;
        } else {
            chars[char] += 1;
        }
    });

    // check if any of the accumulated chars exceed the allowed occurancy
    // of 50% of the words' length.
    _.forIn(chars, function (charCount) {
        if (charCount >= allowedOccurancy) {
            valid = false;
        }
    });

    return valid;
}
function characterOccurance ( stringToTest ) { var chars = { } , allowedOccurancy , valid = true ; stringToTest = _ . toString ( stringToTest ) ; allowedOccurancy = stringToTest . length / 2 ; // Loop through string and accumulate character counts _ . each ( stringToTest , function ( char ) { if ( ! chars [ char ] ) { chars [ char ] = 1 ; } else { chars [ char ] += 1 ; } } ) ; // check if any of the accumulated chars exceed the allowed occurancy // of 50% of the words' length. _ . forIn ( chars , function ( charCount ) { if ( charCount >= allowedOccurancy ) { valid = false ; } } ) ; return valid ; }
Counts repeated characters in a string. When 50% or more characters are the same,
we return false and therefore invalidate the string.
@param {String} stringToTest The password string to check.
@return {Boolean}
Counts repeated characters in a string . When 50% or more characters are the same we return false and therefore invalidate the string .