Home » Developer & Programmer » JDeveloper, Java & XML » Reset expired password with Java
Reset expired password with Java [message #573695] Wed, 02 January 2013 06:44 Go to next message
isri
Messages: 16
Registered: November 2012
Junior Member
Hello,

I'm trying to write short program to reset password on databases. I'm trying to use OCINewPassword property with following code:

public void ResetPassword(String sOldPass, String sNewPass) {

		this.sCurrent = sOldPass;
		this.sNewPassword = sNewPass;

		Properties props;
		Connection conn = null;
		
		try {
			Class.forName("oracle.jdbc.OracleDriver");
		} catch (ClassNotFoundException exp) {
			exp.printStackTrace();
		}

		props = new Properties();

		if (this.sCurrent != null && this.sNewPassword != null) {

			try {
				props.put("user", sUser);
				props.put("password", sCurrent);
				props.put("OCINewPassword", sNewPassword);
				conn = DriverManager.getConnection(this.sUrl, props);

				System.out.println("Password changed successfully");

			} catch (Exception exp) {
				exp.printStackTrace();
			}

			try {
				if (conn != null)
					conn.close();
			} catch (Exception exp) {
				exp.printStackTrace();
			}
		}
	}


Unfortunatelly still geting

java.sql.SQLException: ORA-28001: the password has expired

	at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:113)
	at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
	at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:283)
	at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:278)
	at oracle.jdbc.driver.T4CTTIoauthenticate.receiveOauth(T4CTTIoauthenticate.java:792)
	at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:364)
	at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:454)
	at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165)
	at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
	at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:802)
	at java.sql.DriverManager.getConnection(DriverManager.java:525)
	at java.sql.DriverManager.getConnection(DriverManager.java:140)
	at opr.OraConnect.ResetPassword(OraConnect.java:217)
	at opr.Main.main(Main.java:34)


Could you please help?

Many thanks!
Re: Reset expired password with Java [message #573698 is a reply to message #573695] Wed, 02 January 2013 07:27 Go to previous messageGo to next message
Michel Cadot
Messages: 68625
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
You have to FIRST get and trap the error to be able to change.
In other words, you have to try to connect, get and trap the error, then connect again with the old and new passwords.

Regards
Michel
Re: Reset expired password with Java [message #573808 is a reply to message #573698] Thu, 03 January 2013 05:11 Go to previous messageGo to next message
isri
Messages: 16
Registered: November 2012
Junior Member
Hi Michel,

You mean sth like that?

public void ResetPassword(String sOldPass, String sNewPass) {

		this.sCurrent = sOldPass;
		this.sNewPassword = sNewPass;

		Properties props;
		Connection conn = null;
		
		try {
			Class.forName("oracle.jdbc.driver.OracleDriver");
		} catch (ClassNotFoundException exp) {
			System.out.println(" ERROR1: " + "\t"
					+ exp.getClass().getSimpleName() + "\t\t"
					+ exp.getMessage());
			exp.printStackTrace();
		}

		props = new Properties();

		if (this.sCurrent != null && this.sNewPassword != null) {

			try {
				System.out.println("User: " + this.sUser
						+ "\nUrl: " + this.sUrl);
				props.put("user", this.sUser);
				props.put("password", sCurrent);
				conn = DriverManager.getConnection(this.sUrl, props);

				System.out.println("Connection passed");

			} catch (Exception exp) {
				System.out.println(" ERROR Connection: user: " + this.sUser + ";url: " + this.sUrl + "; Error: "
						+ exp.getClass().getSimpleName() + "; Error message: "
						+ exp.getMessage());
			}
			
			try {
				props.put("user", this.sUser);
				props.put("password", sCurrent);
				props.put("OCINewPassword", sNewPassword);
				conn = DriverManager.getConnection(this.sUrl, props);

				System.out.println("Password changed successfully ");

			} catch (Exception exp) {
				System.out.println(" ERROR Pass reset: user: " + this.sUser + ";url: " + this.sUrl + "; Error: "
						+ exp.getClass().getSimpleName() + "; Error message: "
						+ exp.getMessage());
			}

			try {
				if (conn != null)
					conn.close();
			} catch (Exception exp) {
				System.out.println(" ERROR Conn close: user: " + this.sUser + ";url: " + this.sUrl + "; Error: "
						+ exp.getClass().getSimpleName() + "; Error message: "
						+ exp.getMessage());
			}
		}
	}


Unfortunatelly, it's not working - I'm getting sth like that

Reseting password on XYZ
User: login
Url: jdbc:oracle:thin:@XYZ:123456/XYZ.ABC
Connection passed
Password changed successfully 


But nothing really happens on DB side - password is still the same...

[Updated on: Thu, 03 January 2013 05:12]

Report message to a moderator

Re: Reset expired password with Java [message #573811 is a reply to message #573808] Thu, 03 January 2013 05:21 Go to previous messageGo to next message
Michel Cadot
Messages: 68625
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
But this time you didn't have the "password expire" error, so is it possible thta the password was no more expired?
Or is this possible that new and old given passwords were the same one?

Regards
Michel
Re: Reset expired password with Java [message #573814 is a reply to message #573811] Thu, 03 January 2013 05:36 Go to previous message
isri
Messages: 16
Registered: November 2012
Junior Member
Sorry forgot about that - during the tests my account switch to locked, so I had to unlock it (and change password) 'traditionally'.
Previous Topic: Problem in changing Graph dynamically in IE8. However it's working fine in IE6
Next Topic: XML parsing help
Goto Forum:
  


Current Time: Fri Mar 29 09:10:29 CDT 2024