- 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
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
08-14-2014 04:51 AM
:facepalm:
.setDisplayValue() was exactly what was needed. I'm appalled that it didn't occur to me to try that.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2016 12:00 PM
Hi,
Did it worked for you?? I am trying the same and it is not working for me. Any help on this??
THanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2015 10:38 AM
Hello. As an admin, I went to the User Administration page, pulled up a user and tried to change his password, but the update failed with these messages:
Invalid update.
Match not found, reset to original
Thoughts on this?