Home > Blockchain >  AS400 username and password verification in java. (Problem when putting the wrong credentials)
AS400 username and password verification in java. (Problem when putting the wrong credentials)

Time:01-11

So when i introduce a wrong username and password it should show me only the message:"Intente otra vez"

Here is my code:

try {
            String usuario=txtUsu.getText();
            String password=contrasena.getText();
            ModeloExcel modeloE = new ModeloExcel();
            //loginAS400       
            if(modeloE.loginAS400( usuario, password)==true){
                VistaExcel vistaE = new VistaExcel(usuario, password);
                ControladorExcel contraControladorExcel = new ControladorExcel(vistaE, modeloE);
                try {
                    modeloE.loginAS400(usuario, password);
               } catch (SQLException ex) {
                    Logger.getLogger(VistaLogin.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IOException ex) {
                    Logger.getLogger(VistaLogin.class.getName()).log(Level.SEVERE, null, ex);
                }
                vistaE.setVisible(true);
                vistaE.setLocationRelativeTo(null);
                this.setVisible(false);
            } else if(modeloE.loginAS400( usuario, password)==false){
                JOptionPane.showMessageDialog(null,"Intente otra vez");
                txtUsu.setText("");
                System.exit(0);
            }
        } catch (SQLException ex) {
            Logger.getLogger(VistaLogin.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(VistaLogin.class.getName()).log(Level.SEVERE, null, ex);
        }

and the loginAS400:

public static boolean loginAS400(String usuario, String contrasena) throws SQLException, IOException {
        String serverAS400 = "ip"; 
        Driver d=new com.ibm.as400.access.AS400JDBCDriver();
        DriverManager.registerDriver(d);
        Connection connectionAS400 = DriverManager.getConnection("jdbc:as400://"   serverAS400, usuario, contrasena);
        if (connectionAS400!=null) {
            return true;
        } else {
            return false;
        }
    }

It shows me this...

But as you can see, it shows me the as400 login error. and it keeps showing after every cancel or exit. Only after a few cancels, the program closes and returns me to the login in my project.

So i'm wondering if there is something i can do to make it not show me the AS400 program login.

CodePudding user response:

Looking at the documention at https://www.ibm.com/docs/en/i/7.3?topic=ssw_ibm_i_73/rzahh/javadoc/com/ibm/as400/access/doc-files/JDBCProperties.htm, I see the prompt JDBC property should do the trick.

Use the prompt=false on your JDBC URL, i.e.

Connection connectionAS400 = DriverManager.getConnection("jdbc:as400://"   serverAS400 ";prompt=false', usuario, contrasena);

CodePudding user response:


AS400 username and password verification in java. (Problem when putting the wrong credentials)

It seems that you don't get the error message because your code execution never enters that block of code since connectionAS400 variable of type Connection is not null even if the user is not correct, you need to check for the negative value contained in connectionAS400.

DriverManager.getConnection returns a url or exceptions, you can check the developer reference here: DriverManager Java Developer Reference

  • Related