Symantec IGA

 View Only

Javascipt based BLTH : Generate Temporary Password. 

May 16, 2018 05:00 AM

Credit: Eliran and Chen. 

 

Here is the BLTH code that creates the password with more control.

 

GeneratePassword

This is a Rhino function that gets the number of lower case, upper case, special characters, digits and total number of chars that you want the password to be. The function will return the generated password. This function uses 2 more functions, pickChar and shuffleString.

function GeneratePassword(BlthContext, errorMessage, numChars, numHighChar, numSpec, numNum, numTotal){

                var specials = "!@#$%^&*()_+";

                var charactersSet = 'abcdefghijklmnopqrstuvwxyz';

                var HighCaseSet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';

                var numbers = '0123456789';

                var numOfAll = numTotal - numChars - numSpec - numNum - numHighChar;

                var all = specials + charactersSet + HighCaseSet + numbers;

 

                var newPassword = "";

                newPassword += pickChar(specials,numSpec);

                newPassword += pickChar(charactersSet,numChars);

                newPassword += pickChar(numbers,numNum);

                newPassword += pickChar(HighCaseSet,numHighChar);

                newPassword += pickChar(all,numOfAll);

                newPassword = shuffleString(newPassword);

                return newPassword;

}

 

function pickChar(charString, min, max) {

    var n, chars = "";

 

    if (typeof max === 'undefined') {

        n = min;

    } else {

        n = min + Math.floor(Math.random() * (max - min));

    }

 

    for (var i = 0; i < n; i++) {

        chars += charString.charAt(Math.floor(Math.random() * charString.length));

    }

 

    return chars;

}

 

function shuffleString(inputString) {

    var array = inputString.split('');

    var tmp, current, top = array.length;

 

    if (top) while (--top) {

        current = Math.floor(Math.random() * (top + 1));

        tmp = array[current];

        array[current] = array[top];

        array[top] = tmp;

    }

 

    return array.join('');

}

 

-----------------------------------------------------------------------------------------------------------------------------------------

Here is an example how to run it and save the new password to the user

------------------------------------------------------------------------------------------------------------------------------------------

 

function handleSubmission(BlthContext, errorMessage) {

       var newPass = GeneratePassword(BlthContext, errorMessage, 1, 1, 1, 1, 8);

       BlthContext.getUser().setAttribute("%PASSWORD%",newPass);

       return true;          

}

 

Statistics
0 Favorited
6 Views
0 Files
0 Shares
0 Downloads

Tags and Keywords

Related Entries and Links

No Related Resource entered.