source: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/ChangePwdUsersDB.java@ 25328

Last change on this file since 25328 was 25328, checked in by ak19, 12 years ago

Minor changes, removed debugging statements.

File size: 2.7 KB
Line 
1/*
2 * txt2usersDB.java
3 * Copyright (C) 2008 New Zealand Digital Library, http://www.nzdl.org
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19package org.greenstone.gsdl3.util;
20
21import java.sql.SQLException;
22import org.greenstone.gsdl3.service.Authentication;
23//import org.greenstone.admin.guiext.PropertiesStep;
24
25public class ChangePwdUsersDB {
26
27 public static void main(String[] args) throws SQLException {
28
29 if (args.length!=3){
30 System.out.println("Usage: java org.greenstone.gsdl3.ChangePwdUsersDB <full_path_of_the_usersDB> <username> <password>");
31 System.exit(0);
32 }
33
34 DerbyWrapper dw=new DerbyWrapper();
35
36 String usersDB = args[0];
37 String username = args[1];
38 String password = args[2];
39
40 if(password.length() < 3 || password.length() > 8) {
41 System.err.println("Password should be between 3 and 8 characters (inclusive).");
42 } else {
43 // find the user to modify
44 dw.connectDatabase(usersDB,false);
45 UserQueryResult findUserResult = dw.findUser(username);
46
47 if(findUserResult == null) {
48 System.err.println("Failed to change password. Cannot find user " + username + " in " + usersDB + " database.");
49 }
50 else { // modify existing user data, now we have a (valid) password
51
52 // if any of the other fields are not specified, get them from the database
53 UserTermInfo user = findUserResult.getUserTerms().get(0);
54 String groups = user.groups;
55 String accountstatus = user.accountstatus;
56 String comment = user.comment;
57 String email = user.email;
58
59 // Use the same encryption technique used by the Admin Authentication page
60 // This ensures that the password generated for a string remains consistent
61 password = Authentication.hashPassword(password);
62 //System.err.println("**** Password: " + password);
63
64 //System.err.println("**** " + username + " " + password + " " + groups + " " + accountstatus + " " + comment + " " + email);
65 dw.modifyUserInfo(username, password, groups, accountstatus, comment, email); // remaining fields are allowed to be ""
66 }
67
68 dw.closeDatabase();
69 }
70 }
71}
Note: See TracBrowser for help on using the repository browser.