Check if AS400 (IBMi Power System) Password Expired and Update new Password using Java

You will need to use the Toolbox for Java/JTOpen. Please dow download jt400.jar from https://sourceforge.net/projects/jt400/ OR find it here in your system IFS path /QIBM/ProdData/HTTP/Public/jt400/lib

Verify password

private LoginResponse authenticateAS400(String userId, String password) {  

  LoginResponse response = new LoginResponse();
  boolean success = false;

  try {       
   AS400 system = new AS400();
   success = system.authenticate(userId.trim().toUpperCase(), password.trim());
  } 
  catch(AS400SecurityException e){
   if(e.getReturnCode() == AS400SecurityException.PASSWORD_EXPIRED){
    response.setPasswordExpired(true);
   }
   response.setErrorMessage(e.getMessage());
   e.printStackTrace();
  } 
  catch(Exception e){
   response.setErrorMessage(e.getMessage());
   e.printStackTrace();
  }                       

  response.setSuccess(success);

  return response;

 }
public class LoginResponse {

 boolean success = false;
 boolean passwordExpired = false;
 String errorMessage = "";
 
 public boolean isSuccess() {
  return success;
 }
 public void setSuccess(boolean success) {
  this.success = success;
 }
 public boolean isPasswordExpired() {
  return passwordExpired;
 }
 public void setPasswordExpired(boolean passwordExpired) {
  this.passwordExpired = passwordExpired;
 }
 public String getErrorMessage() {
  return errorMessage;
 }
 public void setErrorMessage(String errorMessage) {
  this.errorMessage = errorMessage;
 }
 
  
}

Updating the password

AS400 system = new AS400("localhost",userId.trim().toUpperCase());
system.changePassword(oldPassword.trim().toUpperCase(), password.trim());

No comments:

Post a Comment

NO JUNK, Please try to keep this clean and related to the topic at hand.
Comments are for users to ask questions, collaborate or improve on existing.