- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2024 09:35 AM - edited ‎03-08-2024 09:36 AM
I'm trying to "disable" local logon for all accounts imported from AD (so that admins and other local accounts can still use local logon) by setting users' passwords to a random string. Here's the script (partially provided by this ServiceNow doc😞
var r = new Packages.java.util.Random();
var str1 = Packages.java.lang.Long.toString(Packages.java.lang.Math.abs(r.nextLong()),36);
var str2 = Packages.java.lang.Long.toString(Packages.java.lang.Math.abs(r.nextLong()),36);
var newPass = str1 + str2;
var gr = new GlideRecord('sys_user');
gr.get('b8b936b31b4ef05023a02173604bcb67');
gr.user_password.setDisplayValue(newPass);
gr.update();
I'm testing on my own non-admin account which is synced from AD. Script output shows successful update, but I am still able to log in with my old password synced from AD.
Any ideas?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-11-2024 07:13 AM
The problem was LDAP authentication was enabled lol...
There were no local passwords because users with authenticating to our LDAP server. Once I disabled this, the script worked fine and I was able to log in with the local scrambled password.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2024 12:17 PM - edited ‎03-08-2024 12:19 PM
Hi @Oliver Anderson ,
You can refer below article here user have tried something similar to your requirement,
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2024 11:59 PM
Pls try this-
// Assuming 'userid' is the username of the user requesting the password reset
var usr = new GlideRecord('sys_user');
usr.addQuery('active', 'true');
usr.addQuery('user_name', userid);
usr.query();
if (usr.next()) {
var newpw = generatePassword(8); // Generate a new password
usr.user_password.setDisplayValue(newpw); // Set the display value for the password
usr.password_needs_reset = true;
usr.update();
}
// Function to generate a random password
function generatePassword(length) {
var availablechars = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
var newPassword = "";
for (var i = 0; i < length; i++) {
var randomNumber = Math.floor(Math.random() * availablechars.length);
newPassword += availablechars[randomNumber];
}
return newPassword;
}
Make sure to replace 'userid' with the actual username of the user requesting the password reset.
Regards,
Amit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2024 11:03 AM
Its my question to, thanks for sharing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-11-2024 07:13 AM
The problem was LDAP authentication was enabled lol...
There were no local passwords because users with authenticating to our LDAP server. Once I disabled this, the script worked fine and I was able to log in with the local scrambled password.