Solved

setEchoChar

Posted on 1997-05-13
7
332 Views
Last Modified: 2012-06-27
I'm using setEchoChar so that a password is displayed as asterisks.  I have a dialog used to change the password where I call setText on the TextField with the setEchoChar set.  The real password is always displayed however instead of the asterisks.  It looks as if the only time asterisks are displayed is when you are actually typing in the TextField but it doesn't work for setText.  How can I get this to work without doing setText("******").
0
Comment
Question by:dsignori
  • 4
  • 2
7 Comments
 
LVL 6

Expert Comment

by:jpk041897
ID: 1220403
setEchoChar() activates a modifier for keyboard input, not for actual display. (I don't know why they designed it this way). You will have to simulate keyboard events to actualy get the behaviour your looking for.

If no one provides a better alternative,(or if you consider this one satisfactory)  I'll send you an answer with some code.
0
 
LVL 6

Expert Comment

by:jpk041897
ID: 1220404
As no one has offere a better alternative, and if you are still interested I'll post you some code as answer.
0
 

Expert Comment

by:chieh061297
ID: 1220405
I assume you are only using setText to setup the dialog so that
when a user brings up a dialog, the password field will be filled
with his default password.

The point to this is that since you don't want anyone to see the
password in the first place, you don't really have to send it
what it is. Instead, if his default password is 6 character,
send the entry box 6 asterisks.

For example, change your
  passwordBox.setText (password);
to
  String str = new String ();
  for (int i = 0; i < password.length (); i++)
    str = new String ("*" + str);
  passwordBox.setText (password);

Or better yet, send a predefined number of asterisks so potential
hackers won't know how many characters is in the default
password:
  passwordBox.setText ("********");

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Expert Comment

by:chieh061297
ID: 1220406
I missed your last sentence in your question:

  "How can I get this to work without doing setText("******")."

Anyway, I tried the following code on my Windows NT using JDK 1.0.2 and 1.1.2:

import java.applet.*;
import java.awt.*;

public class password extends Applet
{
  TextField pw = new TextField ("This is a test.");

  public void init ()
  {
    pw.setEchoCharacter ('*');
    add (pw);
    show ();
    pw.setText ("Neat!");
  }
}

Everything seems to work fine. The text is displayed as asterisks rather than the text. What OS platform and JDK implementation are you using?

0
 

Author Comment

by:dsignori
ID: 1220407
Comment for jpk.  Yes, I would like you to answer and post some code
if you will.  Thanks.
0
 
LVL 6

Accepted Solution

by:
jpk041897 earned 100 total points
ID: 1220408
WARNING: Untested code. I'm posting like this because your quetion is about to drop out of the Awaiting answeres que and I won't actualy have enough time to test untill tuesday. But the code demonstrates the basic idea, which is to override the setText() method to change its default behaviour from drawing text to posting keyboard events.

I'll test and debug it on tuesday unless you post a comment here indicating I should not.

import java.lang.*;
import java.awt.*;

public class pwdTextField extends TextField{
      
      public pwdTextField(){
            super();
      }
      
      public pwdTextField(int cols){
            super(cols);
      }
      
      public pwdTextField(String text){
            super(text);
      }
      
      public pwdTextField(String text, int cols){
            super(text, cols);
      }

      public void setText(String text){
            int i;
            
            for (i = 0; i < text.length(); i++){
                  
                  Event event = new Event(this, Event.KEY_ACTION, text.substring(i,i));
         deliverEvent(event);
       
      }
   }

}
0
 
LVL 6

Expert Comment

by:jpk041897
ID: 1220409
Your question is verry close to beeing automaticaly graded. Why don't you F it sometime tommorow morning (tuesday,16) and send me an e-mail to jkelleghan@usa.net just in case.

I reaaly don't need the points. but you do need a solution so there is no sense in having the thread lost before I can get a definite answer to you.

And since the an answered question may be read by other users in the future, there is no sense in giving it a passing grade before we are sure that the solution posted works.

What do you think?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
DO we need Java installed on a Windows PC and WHY ? 13 98
compre toata in where clue oracle 4 56
eclipse argument 14 53
xampp tool 12 28
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now