I need help urgently.

Discussion in 'Java' started by Abs, Dec 3, 2006.

  1. Abs

    Abs Guest

    Guys, i need a way so that i can mask the password on my program. I
    want the password to appear as **** or something like that. I cant use
    applets, awt or any other thing beyond our ICSE Std X syllabus. Threads
    would be OK i guess but pls try avoiding it. Plz help
    Abs, Dec 3, 2006
    #1
    1. Advertising

  2. Abs wrote:

    Sub: I need help urgently.

    Hire a consultant.

    > Guys, i need a way so that i can mask the password on my program. I
    > want the password to appear as **** or something like that.


    Use a JPasswordField.

    >...I cant use
    > applets, awt or any other thing beyond our ICSE Std X syllabus.


    The 'standard way' to pass an exam is to study for it,
    rather than come to usenet and ask for 'codes'.

    >...Threads
    > would be OK i guess but pls try avoiding it.


    Sure thing.

    Andrew T.
    Andrew Thompson, Dec 3, 2006
    #2
    1. Advertising

  3. Abs

    Simon Brooke Guest

    in message <>, Abs
    ('') wrote:

    > Guys, i need a way so that i can mask the password on my program. I
    > want the password to appear as **** or something like that. I cant use
    > applets, awt or any other thing beyond our ICSE Std X syllabus. Threads
    > would be OK i guess but pls try avoiding it. Plz help


    How the **** are we supposed to know what's in your syllabus? And you'd get
    better help if you put something useful in the subject line.

    If you're writing a console app, read a character from the input stream and
    print an asterisk to the output stream; repeat until you get an end of
    line character. Something like (untested):

    public String getPassword( InputStream in, OutputStream out, String prompt)
    {
    StringBuffer passBuff = new StringBuffer();
    boolean done = false;

    out.print( prompt);

    while ( ! done)
    {
    int c = in.read();

    switch ( c)
    {
    case -1: /* EOF */
    case '\n':
    case '\r':
    /* and any other characters you see as terminating */
    out.println();
    done = true;
    break;
    default:
    passBuff.append( ( char)c);
    out.print( '*');
    break;
    }
    }

    return passBuff.toString();
    }

    The while loop here may lose you marks for style; you should probably
    recode it as a for loop. I used while primarily to make it clearer.

    --
    (Simon Brooke) http://www.jasmine.org.uk/~simon/

    Q: Whats a webmaster?
    A: Like a spider, but nowhere near as intelligent.
    Simon Brooke, Dec 3, 2006
    #3
  4. Abs

    Oliver Wong Guest

    "Simon Brooke" <> wrote in message
    news:...
    > in message <>, Abs
    > ('') wrote:
    >
    >> Guys, i need a way so that i can mask the password on my program. I
    >> want the password to appear as **** or something like that.

    >

    [...]
    >
    > If you're writing a console app, read a character from the input stream
    > and
    > print an asterisk to the output stream; repeat until you get an end of
    > line character.


    I think to be able to usefully fulfill the requirements in a console
    app, you'd need someway of disabling the echoing of input. AFAIK, Java
    doesn't provide any mechanism for doing this. So for a console app, my
    recommendation would be "Don't use Java" for this particular problem.

    - Oliver
    Oliver Wong, Dec 4, 2006
    #4
  5. "Oliver Wong" <> writes:

    > "Simon Brooke" <> wrote in message
    > news:...
    >> in message <>, Abs
    >> ('') wrote:
    >>
    >>> Guys, i need a way so that i can mask the password on my program. I
    >>> want the password to appear as **** or something like that.

    >>

    > [...]
    >>
    >> If you're writing a console app, read a character from the input stream
    >> and
    >> print an asterisk to the output stream; repeat until you get an end of
    >> line character.

    >
    > I think to be able to usefully fulfill the requirements in a console
    > app, you'd need someway of disabling the echoing of input. AFAIK, Java
    > doesn't provide any mechanism for doing this. So for a console app, my
    > recommendation would be "Don't use Java" for this particular problem.
    >


    It looks like Java 1.6 supports this, in java.io.Console.

    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4050435

    has related discussion, and some pointers to third-party packages
    implementing various JNI attacks on the problem.


    --
    Mark Jeffcoat
    Austin, TX
    Mark Jeffcoat, Dec 4, 2006
    #5
  6. On 3 Dec 2006 02:04:59 -0800, Abs wrote:
    > Guys, i need a way so that i can mask the password on my program. I
    > want the password to appear as **** or something like that. I cant use
    > applets, awt or any other thing beyond our ICSE Std X syllabus. Threads
    > would be OK i guess but pls try avoiding it. Plz help


    In a text console on any unix-like platform (you didn't specify
    yours), you can do this to prevent the input from being displayed
    while the password is entered:

    http://groups.google.com/group/comp.lang.java.programmer/msg/a132c7feda18187a

    If you want to display asterisks, you need to set "-icanon min 1" to
    get character-at-a-time input, and do System.out.print("*") for each
    character as it's typed.

    /gordon

    --
    [ don't email me support questions or followups ]
    g o r d o n + n e w s @ b a l d e r 1 3 . s e
    Gordon Beaton, Dec 5, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joey Liang via DotNetMonster.com

    Urgently need help in drop down list..thanx

    Joey Liang via DotNetMonster.com, May 24, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    585
    Joey Liang via DotNetMonster.com
    May 24, 2005
  2. Replies:
    1
    Views:
    320
  3. gauthier
    Replies:
    0
    Views:
    616
    gauthier
    Jun 30, 2005
  4. Zino K via JavaKB.com
    Replies:
    5
    Views:
    458
    Bjorn Borud
    Aug 22, 2005
  5. tracethepath

    RUNNING D PROGRAM...need help urgently..

    tracethepath, Jul 2, 2007, in forum: C Programming
    Replies:
    0
    Views:
    313
    tracethepath
    Jul 2, 2007
Loading...

Share This Page