Random Text and Number and special characters

Status: Closed · Asked by gulito on · 0 views

gulito — Question ·

Hi

I would like to generate initial passwords for our app. That should contain text and numbers and maybe special characters.
I know that I can use the formater to gennerate random text like that:

Number Formatter -> Spreadsheet Functions
RANDBETWEEN(11111111,99999999)
This will generate a random number between 11111111 & 99999999 every time the action is fired.

However I would like to get a combination also with text and maybe special characters.
Is there a possibility to achieve that in pabbly connect?

Thanks for your help.
best
Olivier

Pabblymember11 — Reply ·

Hey @gulito

Certainly, you can create an alpha-numeric password in Pabbly Connect with the help of the Code action step of JavaScript.

function generateRandomPassword(length) {
var charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
var password = "";

// Ensure at least one number in the password
var hasNumber = false;

for (var i = 0; i < length; i++) {
var randomIndex = Math.floor(Math.random() * charset.length);
var character = charset.charAt(randomIndex);

if (!hasNumber && /[0-9]/.test(character)) {
// If no number in password yet, add a number
hasNumber = true;
}

password += character;
}

// If no number in password, add a random number at a random position
if (!hasNumber) {
var randomPosition = Math.floor(Math.random() * length);
var randomNumber = Math.floor(Math.random() * 10);
password =
password.slice(0, randomPosition) +
randomNumber.toString() +
password.slice(randomPosition + 1);
}

return password;
}

var password = generateRandomPassword(10);
return(password);

Back to all forum threads · Log in to reply