Index: /main/trunk/greenstone3/build.xml
===================================================================
--- /main/trunk/greenstone3/build.xml	(revision 25307)
+++ /main/trunk/greenstone3/build.xml	(revision 25308)
@@ -1214,4 +1214,20 @@
 
     </if>
+  </target>
+
+  <!-- This target won't work with Eclipse because the SecureInputHandler used below conflicts with it. 
+    See http://www.dcepler.net/post.cfm/hiding-password-input-in-ant 
+    But you can do: echo mypassword | ant config-admin -->
+  <target name="config-admin" description="Reset admin password">
+    <input addproperty="admin.password" defaultvalue="admin" message="New admin password (3-8 characters):&gt;">
+      <handler classname="org.apache.tools.ant.input.SecureInputHandler" /> <!-- password won't be visible on screen -->
+    </input>
+    <!--<echo>${admin.password}</echo>--> <!-- for testing -->
+    <java classname="org.greenstone.gsdl3.util.ChangePwdUsersDB">
+      <classpath refid="compile.classpath"/> <!--for ${web.lib}/gsdl3.jar and supporting files-->
+      <arg file="${web.home}/sites/localsite/etc/usersDB"/>
+      <arg value="admin"/>
+      <arg value="${admin.password}"/>
+    </java>
   </target>
 
Index: /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/DerbyWrapper.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/DerbyWrapper.java	(revision 25307)
+++ /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/DerbyWrapper.java	(revision 25308)
@@ -345,4 +345,6 @@
 	}
 
+    // findUser(null) will return all users, which is why a UserQueryResult 
+    // (a vector of UserTermInfo) is returned
 	public UserQueryResult findUser(String username) throws SQLException
 	{
@@ -464,7 +466,18 @@
 	public void db2txt()
 	{
-		try
-		{
-			conn.setAutoCommit(false);
+	    System.err.println(db2txtString());		
+	}
+
+	public String db2txtString()
+	{
+	    //String db2txt = "Error in converting db2txt string.";
+	    String db2txt = "";
+		try
+		{
+		    conn.setAutoCommit(false); // An exception at this line can happen when the GS3 tomcat server is already running
+		                               // and GS3 is already accessing the usersDB when this function independently tries to
+		                               // connect to it (via usersDB2txt.java's main(). For an explanation of the possible 
+		                               // reasons, see http://db.apache.org/derby/papers/DerbyTut/embedded_intro.html
+		                               // section "Embedded Derby supports multiple users in one JVM".
 			String sql_list_all_user = "select username, password, accountstatus, comment, email from " + USERS;
 			ResultSet rs = state.executeQuery(sql_list_all_user);
@@ -497,13 +510,14 @@
 				}
 				conn.commit();
-
-				System.err.println("-------------------------------------");
-				System.err.println("USERNAME = " + user.get("username"));
-				System.err.println("PASSWORD = " + user.get("password"));
-				System.err.println("GROUPS = " + returnedGroups);
-				System.err.println("STATUS = " + user.get("status"));
-				System.err.println("COMMENT = " + user.get("comment"));
-				System.err.println("EMAIL = " + user.get("email"));
-				System.err.println("-------------------------------------");
+				
+				StringBuffer buffer = new StringBuffer();//("-------------------------------------");
+				buffer.append("USERNAME = " + user.get("username"));
+				buffer.append("\nPASSWORD = " + user.get("password"));
+				buffer.append("\nGROUPS = " + returnedGroups);
+				buffer.append("\nSTATUS = " + user.get("status"));
+				buffer.append("\nCOMMENT = " + user.get("comment"));
+				buffer.append("\nEMAIL = " + user.get("email"));
+				buffer.append("\n-------------------------------------\n");
+				db2txt = buffer.toString();
 			}
 
@@ -514,4 +528,6 @@
 		{
 			ex.printStackTrace();
+		} finally {
+		    return db2txt;
 		}
 	}
Index: /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/txt2usersDB.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/txt2usersDB.java	(revision 25307)
+++ /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/txt2usersDB.java	(revision 25308)
@@ -38,4 +38,5 @@
 	    dw.connectDatabase(args[1],false);
 	    boolean delete_rows = dw.deleteAllUser();
+	    dw.closeDatabase();
 	    if (!delete_rows){
 		System.out.println("Couldn't delete rows of the users table");
@@ -47,12 +48,39 @@
 	    String accountstatus=null;
 	    String comment=null;
+	    String email=null;
 	    while ((str = in.readLine()) != null) {
 		//ystem.out.println(str);
-		if (str.startsWith("<")){
+		
+		if(str.indexOf(" = ") != -1) { // works with DerbyWrapper.db2txt() and usersDB2txt.java. Fields listed as: USERNAME = admin
+		    String field=str.substring(0,str.indexOf(" = "));
+		    if (field.equalsIgnoreCase("email")){
+			email=str.substring(str.indexOf(" = ")+3,str.length());
+		    }
+		    if (field.equalsIgnoreCase("comment")){
+			comment=str.substring(str.indexOf(" = ")+3,str.length());
+		    }
+		    if (field.equalsIgnoreCase("status")){
+			accountstatus=str.substring(str.indexOf(" = ")+3,str.length());
+		    }
+		    if (field.equalsIgnoreCase("groups")){
+			groups=str.substring(str.indexOf(" = ")+3,str.length());
+		    }
+		    if (field.equalsIgnoreCase("password")){
+			//password=dw.rot13(str.substring(str.indexOf(">")+1,str.length()));
+			password=str.substring(str.indexOf(" = ")+3,str.length());
+		    }
+		    if (field.equalsIgnoreCase("username")){
+			username=str.substring(str.indexOf(" = ")+3,str.length());
+		    }
+		}		
+		else if (str.startsWith("<")){ // fields listed as: <username>admin
 		    String field=str.substring(1,str.indexOf(">"));
+		    if (field.equals("email")){
+			email=str.substring(str.indexOf(">")+1,str.length());
+		    }
 		    if (field.equals("comment")){
 			comment=str.substring(str.indexOf(">")+1,str.length());
 		    }
-		    if (field.equals("enabled")){
+		    if (field.equals("enabled") || field.equals("status")){
 			accountstatus=str.substring(str.indexOf(">")+1,str.length());
 		    }
@@ -61,5 +89,6 @@
 		    }
 		    if (field.equals("password")){
-			password=dw.rot13(str.substring(str.indexOf(">")+1,str.length()));
+			//password=dw.rot13(str.substring(str.indexOf(">")+1,str.length()));
+			password=str.substring(str.indexOf(">")+1,str.length());
 		    }
 		    if (field.equals("username")){
@@ -67,8 +96,10 @@
 		    }
 		}
-		if (str.equals("----------------------------------------------------------------------")){
-		    if ((username!=null) && (password!=null) && (groups!=null) && (accountstatus!=null) && (comment!=null)){
+		else if (str.equals("----------------------------------------------------------------------")
+			 || str.equals("-------------------------------------")) {		    
+		    
+		    if ((username!=null) && (password!=null) && (groups!=null) && (accountstatus!=null) && (comment!=null) && (email!=null)) {
 			dw.connectDatabase(args[1],false);
-			dw.addUser(username, password, groups, accountstatus, comment);
+			dw.addUser(username, password, groups, accountstatus, comment, email);
 			username=null;
 			password=null;
@@ -76,5 +107,13 @@
 			accountstatus=null;
 			comment=null;
-			dw.connectDatabase(args[1],false);
+			email=null;
+			//dw.connectDatabase(args[1],false); // should this be closeDatabase()????
+			dw.closeDatabase();
+		    }
+		}
+		else { // encrypted passwords can span multiple lines for some reason
+		       // assume that is the case here
+		    if(password != null) { 
+			password = password + "\n" + str;
 		    }
 		}
