Hi All,I need to generate and set a random password for the selected user.Can anyone help me on this?Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-06-2016 03:10 AM
Hi All,I need to generate and set a random password for the selected user.Can anyone help me on this?Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-06-2016 05:20 AM
helpful.
Thanks Mihir
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2016 02:30 AM
HI Mihir
I am trying below code
function onAfter(current, previous) {
//This function will be automatically called when this rule is processed.
if (current.u_duration == '4') {
gs.log("it is 4");
// Set due date to 4 hours ahead of current time
current.u_valid_till = gs.hoursAgo(-4);
}
if (current.u_duration == '6') {
gs.log("it is 6");
// Set due date to 6 hours ahead of current time
current.u_valid_till = gs.hoursAgo(-6);
}
if (current.u_duration == '8') {
// Set due date to 8 hours ahead of current time
current.u_valid_till = gs.hoursAgo(-8);
}
}
but it is not working as expected...
PS:checked the logs to ensure fields name have been correctly mentioned or not...logs are coming
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-27-2020 12:45 AM
To generate password with restrictions, you can use regex. Below ex. using regex condition for containing at least one capital letter, one small letter and one numerical.
var string_length = 6;
var patern=/^(?=.*[0-9])(?=.*[a-zA-Z])([a-zA-Z0-9]+)$/;
var charList='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
do{
var password='';
for(var i=0;i<6;i++){
password+=charList.charAt(Math.random()*charList.length);
}
}while(!patern.test(password));

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2017 11:22 PM
This example randomly generates a password from a base word and numbers. The base word is selected depending on the credential store. The code would be contained in the Script field of an extension script named SamplePasswordGenerator:
var SamplePasswordGenerator = Class.create();
SamplePasswordGenerator.prototype = {
category: 'password_reset.extension.password_generator', // DO NOT REMOVE THIS LINE!
/**********
* Returns an auto-generated string password.
* This sample randomly generates 4 digits to add to the password.
*
* @param params.credentialStoreId The sys_id of the target password reset credential store to generate
* a password for (table: pwd_cred_store)
* @return An auto-generated string password
**********/
process: function(params) {
var basePassword;
var gr = new GlideRecord('pwd_cred_store');
gr.addQuery('name', 'Local ServiceNow Instance');
gr.query();
if (gr.next()) {
if (params.credentialStoreId == gr.getValue('sys_id'))
basePassword = "Password";
else
basePassword = "Dorwssap";
}
return this.generateSimple(basePassword);
},
generateSimple : function(base) {
var pwd = base;
var numbers = '0123456789';
var length = 4;
for (var i = 0, n = numbers.length; i < length; i++) {
pwd += numbers.charAt(Math.floor(Math.random() * n) +1);
}
return pwd;
},
type: 'SamplePasswordGenerator'
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-16-2020 09:30 PM
Hi Sushant,
Thank you for the script.
I have a similar kind of requirement. I have enabled the script from the password reset application.
I want to know how this functionality works.
Regards,
Sailesh J