Thursday, February 14, 2013

Password Reset Tool for Google Apps

Last August we rolled out Google Apps at my school. It is getting used in some really creative ways, but because we are not yet one to one, users are not logging in often enough to remember their passwords. So we get a lot of help desk calls to reset passwords. I know it is not the most secure, but to keep it simple, we have a default password that we always use when we reset. To do this in the control panel, you have to browse for the user, then type in the new password twice. Doing this often gets old. So I wrote a simple script where all you have to do is type in the user name. (This is the email address without the domain.) Next a confirmation screen displays the user's first and last name. One final click and the password is reset to your predetermined default password.

Set up is fairly simple, you can just copy and paste the code from below into a Google Apps Script File, or click here to create your own copy by selecting File -> Make a Copy.

Once you have the Google Apps Script file open, the first step is to change the default password. Go to line 104 and change the red text inside the quotes to your default reset password. Next you will have to deploy it as a web app. To do that click File -> Manage Versions.



Then just click save new version. (You don't have to type anything in the box.) Now click Publish -> Deploy as web app.




Choose the settings as shown below. (Of course the last one will show your domain, not lths.org)



Now the web app is deployed. Use the link that pops up to share it. The final step is to control which users have access to this script. You do this by granting access to the provisioning API in the Google Apps Control Panel. To do this you will need super admin rights to the control panel.

Start by going to the Domain Settings tab, then the Admin roles tab. Then click create new role. Give the new role a name. (If you prefer, you can use an existing user created role)



Within this role, scroll down to the bottom and look for the Provisioning API's section. Click users. (This should automatically check the 4 columns to the right.) Click save changes.



Finally, assign admins to this role. They will have to authorize the scrip the first time they use it.


// This the initial app screen
function doGet() {
//create the application
var app = UiApp.createApplication();
//create the vertical panel to hold widgets
var vp = app.createVerticalPanel().setId('vp');
//style the vertial panel
vp.setBorderWidth(5).setStyleAttribute("border-color", "maroon").setStyleAttribute("font-weight", "bold");
//Create the label, text input box and button widgets
var label = app.createLabel('Enter the username that you would like to reset.');
var input = app.createTextBox().setName('input').setId('input');
var button = app.createButton('Submit');
//add the widgets to the vertical panel
vp.add(label);
vp.add(input);
vp.add(button);
//add the vertical panel to the app
app.add(vp);
//create a server handler for the next function
var handler = app.createServerHandler('confirm');
//add the text input box as a callback element to the server handler
handler.addCallbackElement(input);
//assign the server handler to the button
button.addClickHandler(handler);
return app;
}
//this function will confirm that we have the right user
function confirm(e) {
//get the app instance
var app = UiApp.getActiveApplication();
//get the existing vertical panel and make it invisible, I probably could just clear widgets instead
vp = app.getElementById('vp');
vp.setVisible(false);
//create and style a new panel
vp2 = app.createVerticalPanel().setId('id2');
vp2.setBorderWidth(5).setStyleAttribute("border-color", "maroon").setStyleAttribute("font-weight", "bold");
//get the value from the text input box
username = e.parameter.input;
//create a hidden widget that will pass the value of the username to the next function
hidden = app.createHidden('username',username).setId('hidden');
app.add(hidden);
//get the instance of the user
user = UserManager.getUser(username);
//get the first and last name of the user
givenName = user.getGivenName();
familyName = user.getFamilyName();
//create a label and button widgets
label = app.createLabel('Clicking the Reset button below will reset the password for '+givenName+" "+familyName);
button = app.createButton('Reset');
//add the widgets to the vertical panel
vp2.add(label);
vp2.add(button)
//add the vertical panel to the app
app.add(vp2);
//create a server handler for the next function
var handler = app.createServerHandler('reset');
//add the hidden widget as a callback element to the server handler
handler.addCallbackElement(hidden);
//assign the server handler to the button
button.addClickHandler(handler);
return app;
}
//this function will actually reset the password
function reset(e) {
//get the app instance
var app = UiApp.getActiveApplication();
//get the existing vertical panel and make it invisible, I probably could just clear widgets instead
vp2 = app.getElementById('id2');
vp2.setVisible(false);
//get the value from the hidden widget
username = e.parameter.username
//get the instance of the user
user = UserManager.getUser(username);
//SET YOUR DEFAULT PASSWORD HERE
var password = 'your_custom_default_password'
//reset the password to porters12 and force a password change
user.setChangePasswordAtNextLogin(true).setPassword(password);
//create and style a new panel
vp3 = app.createVerticalPanel();
vp3.setBorderWidth(5).setStyleAttribute("border-color", "maroon").setStyleAttribute("font-weight", "bold");
//create a label that logs what happened
label = app.createLabel('The password for '+username+' has been reset to the default.');
//add the label to the panel and panel to the app
vp3.add(label);
app.add(vp3);
return app;
}
view raw reset hosted with ❤ by GitHub

4 comments:

  1. Good blog. Also visit http://www.cloudcodes.com/

    ReplyDelete
  2. Thanks brainmine, i like the website you have suggested. Infact the password policy tool is very useful . Folks try it out password reset tool for google apps Visit for more information at http://www.cloudcodes.com/password-policy.html

    ReplyDelete
  3. Excellent article.I am very happy to see this type article .I am also trying to write this type article with the help of custom essay writing services guidelines.I am eagerly waiting for your new stuff.

    ReplyDelete
  4. We have some good suggestions to reset password by using Google App. The author explained it in a good manner and the screenshots pass the idea quickly. It helps the users to catch the procedures.

    http://essaywriting-servicereviews.com/Forum-Health-and-Food
    http://essaywriting-servicereviews.com/Forum-Cinema-TV-Shows-Music
    http://essaywriting-servicereviews.com/Forum-Religion-Spirituality

    ReplyDelete