Showing results for 
Search instead for 
Did you mean: 

How to autogenerate a specific password

New Contributor

I am trying to create an account in Google AD for which there are mandatory fields such as given name, surname, email and password. For the password, I would like to auto generate random passwords of 8 characters of which 2 are uppercase, 1 number and 1 special character. Is there an expression that could help me achieve this?


Valued Contributor

Hi @VincyJelsingh ,

The following expression does the charm, try it and let me know:

Math.randomUUID().substring(0,8).split('').map((x,index,arr)=> x == arr.find(y=>!isNaN(parseInt(y))) ? x.replace(x,['`','!','#','$','%','^','&','*'][index]) : x).join('').toUpperCase()



New Contributor

Hi @bojanvelevski,

Thank you for the response. 

I tried the provided expression but it sometimes executes an expression with more than 2 numbers, with no lowercase characters and more than 1 symbol. I would prefer to have the expression with 8 characters which have 2 uppercase, 1 symbol and 1 number.

Valued Contributor

hey @VincyJelsingh ,

The following expression is rather complex and ugly looking but it does the job. If I think of a simpler solution, I will add it as well, but for now you can use this one. 

x==x.toUpperCase()? ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'][Math.floor(Math.random()*15)] : ['a', 'b','c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's','t', 'u', 'v', 'w', 'x', 'y', 'z'][Math.floor(Math.random()*10)*2]).concat(['!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '+', '-', '.', '~', '|', '<', '>', '=', '-', '_', '/', ':', ';', '?', '[', ']', '{', '}', '~'][Math.floor(Math.random()*15)]).concat(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'][Math.floor(Math.random()*10)])

Thank you for this solution. But this provides the password as an Array list while I am looking for a string password which has exactly 8 characters (this includes 1 upper case, 1 number, 1 special character)