Monday, January 6, 2014

Can we set user password?

As administrator we often get questions from our user, " can you check what is my password? ", hmmmm, user often think it like some legacy application, where system admin able to see or modify it as we would like.

But, is different, system admin not able to see or modify user password. We often offer the user to reset their password, where will email that user with instruction to set new password by  their own. And it works fine.

But again, some user (read: senior management) not really want to bother by checking email and so on, even this request is come from his/her secretary. So how? No problem, we can change user email to her secretary email, secretary confirm email change in her email (although also will email to the original email that her email has been changed to new one), and reset password. It works, yay!!! 

But, how to change back the user email to the original one? The senior management need to click a link again in her email (she may have hundreds or thousands email never read). Problem.

So, I just start think if there is a way just to set user password easily without have to go through such complicated process? It is worst when the user is going to present something in 5 minutes and we do not have much time to do above process. So, can we set user password?

YES, it is possible, even this function is not exist in configuration menu, but kind enough to provide system admin with Developer Console. Yes, Developer Console is for developer as it named, but admin also can use it for other purpose, like set user password, yay!!!

How? It is easy, just few click and copy paste a sentence will do. Go to your name and click Developer Console menu. 

It will open new window and you need to copy and paste below sentence to the Execute textbox.

System.setPassword('00550000000rlrX', 'hello123');

00550000000rlrX is the User Id, if you are admin, you should now this Id well, and hello123 is the new password to set.

But, if you still too lazy to check the User Id and user pass you their username, you can just copy and paste statement below into Apex Code execute box:

System.setPassword([SELECT Id FROM User WHERE username=''].Id, 'hello123');

Below sample script to set password of all active user in one go:

List<User> userList = new List<User>();
userList = [SELECT Id from User WHERE IsActive = true];
for (User u : userList)
    System.setPassword(u.Id, 'hello123');
    System.debug('DONE: ' + u.Id);

You can modify SOQL above as the need, may be to include only profile = "Sales Rep".

All statements above is apex code, but we can utilize it for other productive work as needed. 


Post a Comment

| ,