How can this password generate code be adjusted or improved, so that it does not repeat characters in the output.
Currently it generates a password like this: b5$b1#q2@w6@R1@K&
I would like it to look like this: %5!L4j@vd4y!x7JJ
Code:
function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var menu = [
{name: "Password Generator", functionName: "password_generator"}
];
ss.addMenu("Disc Activity Menu", menu);
}
function password_generator( len ) {
var length = (len)?(len):(16);
var string = "abcdefghijklnopqrstuvwxyz"; //to upper
var numeric = '0123456789';
var punctuation = '!@#$%&?';
var password = "";
var character = "";
var crunch = true;
while(password.length<length) {
entity1 = Math.ceil(string.length * Math.random()*Math.random());
entity2 = Math.ceil(numeric.length * Math.random()*Math.random());
entity3 = Math.ceil(punctuation.length * Math.random()*Math.random());
hold = string.charAt( entity1 );
hold = (entity1%2==0)?(hold.toUpperCase()):(hold);
character += hold;
character += numeric.charAt( entity2 );
character += punctuation.charAt( entity3 );
password = character;
}
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var activeRow = ss.getActiveRange().getRowIndex();
sheet.getRange("B"+activeRow).setValue(password);
}