Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   I need help urgently. (http://www.velocityreviews.com/forums/t389131-i-need-help-urgently.html)

Abs 12-03-2006 10:04 AM

I need help urgently.
 
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


Andrew Thompson 12-03-2006 10:34 AM

Re: I need help urgently.
 
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.


Simon Brooke 12-03-2006 10:48 AM

Re: I need help urgently.
 
in message <1165140299.091562.62950@16g2000cwy.googlegroups.c om>, Abs
('Abhishek.RShetty@gmail.com') 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@jasmine.org.uk (Simon Brooke) http://www.jasmine.org.uk/~simon/

Q: Whats a webmaster?
A: Like a spider, but nowhere near as intelligent.

Oliver Wong 12-04-2006 10:03 PM

Re: I need help urgently.
 
"Simon Brooke" <simon@jasmine.org.uk> wrote in message
news:9kma44-ici.ln1@gododdin.internal.jasmine.org.uk...
> in message <1165140299.091562.62950@16g2000cwy.googlegroups.c om>, Abs
> ('Abhishek.RShetty@gmail.com') 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



Mark Jeffcoat 12-04-2006 11:49 PM

Re: I need help urgently.
 
"Oliver Wong" <owong@castortech.com> writes:

> "Simon Brooke" <simon@jasmine.org.uk> wrote in message
> news:9kma44-ici.ln1@gododdin.internal.jasmine.org.uk...
>> in message <1165140299.091562.62950@16g2000cwy.googlegroups.c om>, Abs
>> ('Abhishek.RShetty@gmail.com') 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_id=4050435

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


--
Mark Jeffcoat
Austin, TX

Gordon Beaton 12-05-2006 07:14 AM

Re: I need help urgently.
 
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....32c7feda18187a

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


All times are GMT. The time now is 09:38 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57