-------------------------------------------------
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
//**************************************************************************
***
//
//Module:
//ChangePasswordEntry
// @author Kimball Dlouhy
//
//Call Syntax:
//http://my.domain.com:9000/ChangePasswordEntry?
// strHost=beans&strSID=palpha
//
//Arguments:
// strHost The host that the database resides on
// strSID The Oracle SID of the database
//
//Details/Notes:
//This servlet creates a change password form and populate some hidden form
//fields with the Host and SID to pass to ChangePassword which
//actually atttempts to change the database password.
//**************************************************************************
***
//Module History:
//When Who What
//07/01/2002 K Dlouhy Created.
//**************************************************************************
***
public class ChangePasswordEntry extends HttpServlet
{
private static final String CONTENT_TYPE = "text/html;
charset=windows-1252";
public void init(ServletConfig config) throws ServletException
{
super.init(config);
}
public void doGet(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException
{
Vector vBodyElements = new Vector(100, 100);
String strHost = "";
String strSID = "";
String strBody = "";
boolean bOK = true;
// get the values of the parameters
try {
strHost = request.getParameter("strHost");
strSID = request.getParameter("strSID");
} catch(Exception e) {
strBody = e.toString();
bOK = false;
}
//make sure that all fields are filled in and that the new password
entries
match
if (strHost == null || strHost == "") {
strBody = "\nMissing Host name.";
bOK = false;
} else if (strSID == null || strSID == "") {
strBody = "\nMissing Oracle SID.";
bOK = false;
}
if (bOK) {
strBody += "
Change Password
\n";
strBody += "\n";
strBody += "\n";
strBody += "\n";
strBody += " \n";
strBody += "\n";
}
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("");
out.println("ChangePasswordEntry");
out.println("");
out.println(strBody);
out.println("");
out.close();
}
}
--------------------------------------------------------
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import javax.sql.*;
import java.sql.*;
//**************************************************************************
***
//Module:
//ChangePassword
// @author Kimball Dlouhy
//
//Call Syntax:
//http://my.domain.com:9000/tomcat/ChangePassword?
// strHost=beans&strSID=palpha&strUserName=flinstone&
// strOldPassword=fred&strNewPassword=wilma&strRetypePassword=wilma
//
//Arguments:
// strHost The host that the database resides on
// strSID The Oracle SID of the database
// strUserName The Oracle user name whose password you want to
change
// strOldPassword The existing oracle password
// strNewPassword The new password
// strRetypePassword Verification of the new password
//
//Details/Notes:
//This servlet connects to the database with the user name and old password
//and then attempts to change the Oracle password. The success or failure is
//sent back as an HTML page.
//**************************************************************************
***
//Module History:
//When Who What
//07/01/2002 K Dlouhy Created.
//**************************************************************************
***
public class ChangePassword extends HttpServlet
{
private static final String CONTENT_TYPE = "text/html;
charset=windows-1252";
public void init(ServletConfig config) throws ServletException
{
super.init(config);
}
public void doPost(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException
{
Vector vBodyElements = new Vector(100, 100);
String strHost = "";
String strSID = "";
String strUserName = "";
String strOldPassword = "";
String strNewPassword = "";
String strRetypePassword = "";
boolean bOK = true;
int n = 0;
// get the values of the parameters
try {
strHost = request.getParameter("strHost");
strSID = request.getParameter("strSID");
strUserName = request.getParameter("strUserName");
strOldPassword = request.getParameter("strOldPassword");
strNewPassword = request.getParameter("strNewPassword");
strRetypePassword = request.getParameter("strRetypePassword");
} catch(Exception e) {
vBodyElements.addElement(e.toString());
bOK = false;
}
// Load the Oracle JDBC driver
try {
Class.forName ("oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException ex) {
vBodyElements.addElement("\nUnable to find Oracle Driver Class " +
ex.toString());
bOK = false;
}
if (bOK) {
changePassword(vBodyElements, strHost, strSID, strUserName,
strOldPassword, strNewPassword, strRetypePassword);
}
response.setContentType(CONTENT_TYPE);
PrintWriter pwOut = response.getWriter();
pwOut.println("");
pwOut.println("ChangePassword");
pwOut.println("");
pwOut.println("");
pwOut.println("Change Password Results");
pwOut.println("
");
pwOut.println("");
pwOut.println("
");
for (n = 0; n < vBodyElements.size(); n++) {
pwOut.println("
" + vBodyElements.elementAt(n).toString() + "
");
}
pwOut.println("");
pwOut.println("\n\n
\n");
pwOut.println("\n");
pwOut.println("\n\n");
pwOut.println("");
pwOut.close();
}
//**************************************************************************
***
//Module:
//ChangePassword
// @author Kimball Dlouhy
//
//Call Syntax:
//changePassword( vBodyElements, "beans", "palpha", "flinstone", "fred",
"wilma",
// "wilma")
//
//Arguments:
// vBodyElements The vector that holds the body of the HTML page
// strHost The host that the database resides on
// strSID The Oracle SID of the database
// strUserName The Oracle user name whose password you want to
change
// strOldPassword The existing oracle password
// strNewPassword The new password
// strRetypePassword Verification of the new password
//
//Details/Notes:
//This method connects to the database using JDBC with the user name and old
//password and then attempts to change the Oracle password using a stored
//procedure in the database.
//**************************************************************************
***
//Module History:
//When Who What
//07/01/2002 K Dlouhy Created.
//**************************************************************************
***
public void changePassword(Vector vBodyElements, String strHost, String
strSID, String strUserName, String strOldPassword, String strNewPassword,
String
strRetypePassword) {
Connection conn = null;
//make sure that all fields are filled in and that the new password
entries
match
if (strHost == null || strHost == "") {
vBodyElements.addElement("\nMissing Host name.");
} else if (strSID == null || strSID == "") {
vBodyElements.addElement("\nMissing Oracle SID.");
} else if (strUserName == null || strUserName.equals("")) {
vBodyElements.addElement("\nMissing user name.");
} else if (strOldPassword == null || strOldPassword.equals("")) {
vBodyElements.addElement("\nMissing old password.");
} else if (strNewPassword == null || strNewPassword.equals("")) {
vBodyElements.addElement("\nMissing new password.");
} else if (strRetypePassword == null || strRetypePassword.equals("")) {
vBodyElements.addElement("\nMissing retype new password.");
} else if (strNewPassword.equalsIgnoreCase(strRetypePassword) == false)
{
vBodyElements.addElement("\nThe new password was typed
inconsistently.");
} else {
try {
if (conn == null || conn.isClosed()) {
// Connect to the database. To connect to a remote database,
// insert the connect string after the @ sign in the connection
URL.
conn = DriverManager.getConnection
("jdbc:oracle:thin:@"+strHost+":1521:"+strSID, strUserName, strOldPassword);
}
try {
//create the statement
CallableStatement l_stmt =
conn.prepareCall("begin
SMITHS_DBA.DBA_USER_PACKAGE.CHANGE_PASSWORD(?,?); end;");
// Binds the parameter Types and their types
l_stmt.setString(1,strUserName);
l_stmt.setString(2,strNewPassword);
// Execute the callable statement
l_stmt.execute();
// close the statement
l_stmt.close();
vBodyElements.addElement("\nYour password has been successfully
changed.");
}catch (SQLException ex) { // Trap SQL Errors
vBodyElements.addElement("\nError while Calling PL/SQL Procedure "
+
ex.toString());
}
conn.close();
}catch (SQLException ex) { // Trap SQL Errors
vBodyElements.addElement("\nError connecting to database " +
ex.toString());
}
}
}
}
--------------------