Skip to main content


No replies
Joined: 2005-09-06

Hi everyone,

I really need some advice and guidance on the following code

<br />
import javax.swing.*;<br />
import java.util.*;</p>
<p>public class PopupAuthenticator<br />
    extends Authenticator {</p>
<p>  public PasswordAuthentication<br />
      getPasswordAuthentication() {<br />
    String username, password;</p>
<p>    String result = JOptionPane.showInputDialog(<br />
      "Enter 'username,password'");</p>
<p>    StringTokenizer st =<br />
      new StringTokenizer(result, ",");<br />
    username = st.nextToken();<br />
    password = st.nextToken();</p>
<p>    return new PasswordAuthentication(<br />
      username, password);<br />
  }<br />
}<br />

As you guys see above there is JOptionPane that requests both the username and password to access a http website, but i have a dilemma about someting about the method getPasswordAuthentication() that i am supposed to overide.

The thing is i am afraid the getPasswordAuthentication() method may actually return the value of the of both the username and password before the user has even had the chance to type in the correct
username and password.

As you guys can see that the gui that i set gets the value of the input optionpane and i was hoping that that the function returns after the user had pressed "OK" but the thing is i suspect that the function may be returning as soon as the option pane is shown thus causing both the values of the username and password to be null.

Am i using the Authenticator class with gui the correct way or am i missing something??

I really hope someone can explain to me in detail on how this Authenticator class works and maybe help suggest a possible solution that can help me out of my dillema.

Any help is greatly appreciated

Thank You

Yours Sincerely

Richard West