- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2014 06:40 AM
Something that's come up a couple of times, now, is the need to set a default password for a set of users (generally because we're about to kick off UAT). I've tried scripting it before, and have never had any success and inevitably have to just do it by hand... which bothers me.
I've tried doing it the straightforward way:
var gr = new GlideRecord('sys_user');
if (gr.get(userId)) {
gr.user_password = newPassword;
gr.update();
}
Having seen GlideEncrypter using 2-way encrypted fields, I've tried that:
var gr = new GlideRecord('sys_user');
if (gr.get(userId)) {
var encrypter = new GlideEncrypter();
gr.user_password = encrypter.encrypt(newPassword);
gr.update();
}
I've also looked at the business rule that encrypts password & password2 system properties, which gets me this (which also doesn't work):
var gr = new GlideRecord('sys_user');
if (gr.get(userId)) {
var cryptoService = GlideCryptoService.getInstance();
gr.user_password = cryptoService.encryptWithAnyCKP(newPassword);
gr.update();
}
None of these actually set a password that can actually be authenticated against.
What am I missing?
Solved! Go to Solution.
- Labels:
-
Service Mapping
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2014 11:33 AM
I was just installing the self-service password reset feature, and here is the code they use in the script include. There is one distinct difference compared to what you have tried, it sets the display value for the password. I hope this helps!
var usr = new GlideRecord('sys_user');
usr.addQuery('active', 'true');
usr.addQuery('user_name', userid);
usr.query();
...
newpw = "";
var availablechars = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
for(var x = 0; x < 8; x++) {
randomNumber = Math.floor(Math.random() * availablechars.length);
newpw += availablechars[randomNumber];
}
usr.user_password.setDisplayValue(newpw);
usr.password_needs_reset = true;
usr.update();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2016 03:48 PM
Trevor
Excellent - usr.user_password.setDisplayValue(newpw); solved my issue with encryption.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2018 04:06 AM
Will this reset for all the users? What if I only want to do like 50 users?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2015 06:47 AM
Hi, you can try the utility "Password Generator" on ServiceNow Share
It is designed to reset password (one default or random) of multiple users. You can define a filter to find users and setup password and notification options. Can be used for UAT, during release change, within ITOM etc. Tested with >65k users without any problems because of async procedure.
Cheers,
Kostya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2018 10:51 AM
Hi!
Do you how it can be installed in our test environment?
I download it and it is just an XML
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2016 01:49 PM
Oh great. It worked. Thanks