Hi All,I need to generate and set a random password for the selected user.Can anyone help me on this?Thanks

kirti0604
Kilo Contributor

Hi All,I need to generate and set a random password for the selected user.Can anyone help me on this?Thanks

11 REPLIES 11

Sailesh4
Giga Expert

Please try below code and see if it works for you.

 

After BR

sys_user

var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
var string_length = 8;
var randomstring = '';

for (var i = 0; i < string_length; i++) {
var rnum = Math.floor(Math.random() * chars.length);

randomstring += chars.substring(rnum, rnum + 1);

//gs.eventQueue()
}

gs.eventQueue("user.password", current, randomstring, current.email);

current.user_password.setDisplayValue(randomstring);
current.password_needs_reset = true;
current.update();

Dan_Berglin
Giga Expert

Hi,

There's a built in class and method for this on server side;
Example:

GlideSecureRandomUtil.getSecureRandomString(8)