title: How to handle (failed) login attempts with Smack XMPP API
body: <p>I'm developing a chat server based on XMPP and Smack API, which connects to an Openfire server (Hosted by a friend who is also developing this with me).</p>
  
  <p>So, I started programming it just a few days ago (Netbeans on OS X 10.8), and today I went on to the connection and login aspects.</p>
  
  <p>I can login perfectly with the right choice of username+password :P but I don't know how to handle an invalid login attempt and let the app show a message and then allowing the user to retry.</p>
  
  <p>Here's my code, which fires after user has pressed a button in my Swing JForm:</p>
  
  <p>(Note: XMPPConnection object is already created in another class, and the connection has been made to the server. You can see I'm calling the object from that another class)</p>
  
  <pre><code>private void btnIniciarSesionActionPerformed(java.awt.event.ActionEvent evt) {                                                 
      String Usuario = txtUsuario.getText();
      String Password = new String (pwdContrasena.getPassword());
  
      if (Usuario.equals("") || Password.equals("")){
          // Missing data
          JOptionPane.showMessageDialog(null, "Missing data");
      }
      else{
          //Try to login
          try{
              Proyecto_chat.conexion.login(Usuario, Password, "x");
          }
          catch (XMPPException ex){
              Logger.getLogger(Ventana_login.class.getName()).log(Level.SEVERE, null, ex);
              // Problem
          }
          if (Proyecto_chat.conexion.isAuthenticated() == true){  //Login has been successful
              jLabel1.setVisible(false);
              System.out.println("Authenticated as " + Usuario);
              JOptionPane.showMessageDialog(null, "Authenticated as " + Usuario);
              //Exit login window and carry on  
          }
          else{
              JOptionPane.showMessageDialog(null, "login error");
          }
      }
  }
  </code></pre>
  
  <p>Should I play with that exception I'm getting? -></p>
  
  <pre><code>SEVERE: null
  SASL authentication DIGEST-MD5 failed: not-authorized: 
  at org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java:337)
  at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:203)
  at proyecto_chat.Ventana_login.btnIniciarSesionActionPerformed(Ventana_login.java:159)
  at proyecto_chat.Ventana_login.access$100(Ventana_login.java:15)
  at proyecto_chat.Ventana_login$2.actionPerformed(Ventana_login.java:73)
  at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
  (...) more lines that I think are not critical for this
  </code></pre>
  
  <p>As passwords are stored in plain text (University project, so it doesn't matter) for simplifying changing them from inside the application, I can connect to the database (PostgreSQL in remote server) from the client computer, and check the passwords and only do 'conexion.login' if user&amp;pass matches, but that would be... you know... wrong</p>
  
  <p>After looking around on the web with no luck, I decided to head over here, ask, go to sleep and wake up next morning with some suggestions ;)
  Help shall be appreciated</p>