Code example for PasswordCallback

Methods: clearPasswordgetPassword

0
    if ( m_callbackHandler == null ) {
      throw new LoginException( "Error: no CallbackHandler available " +
          "to collect authentication information" ); 
    } 
    NameCallback      nc         = new NameCallback( "User name: ", "guest" );
    PasswordCallback  pc         = new PasswordCallback( "Password: ", false );
    Callback[]        callbacks  = {nc, pc};
    String            username   = null;
    String            password   = null;
    try { 
      m_callbackHandler.handle( callbacks );
      username = nc.getName();
      char[]  tmpPassword  = pc.getPassword();
      if ( tmpPassword != null ) {
        m_credential = new char[tmpPassword.length];
        System.arraycopy( tmpPassword, 0, m_credential, 0, tmpPassword.length );
        pc.clearPassword();
        password = new String( m_credential );
      } 
    } 
    catch ( java.io.IOException ioe ) {
      throw new LoginException( ioe.toString() );
Connect your IDE to all the code out there  Get Codota for Java