• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Problem in Password encryption

 
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI

I have a java program that will create a property file in that I have to write the user Id and password. But the password has to be encrypted.

The java program will get the inputs from the user after running this program i will get the user id input as : ramesh
and password as : ramesh. After that I will encrypt the password and then writing into property file.

Here the problem is I want to hide or (as to show as ****)the password while the user is typing..

HOw to do this in normal java class.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check out the javax.swing.JPasswordField class.

If you encrypt the user's password, how (and where) will you store the encryption key? You've simply transformed the problem of storing a password into the problem of storing an encryption key, which doesn't buy you much in terms of security.
 
Meet Gaurav
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI

Thanks for the reply

This is not a swing application..Basic java class. Am using a diff. logic for encryption and then saving this in a property File.

Am running this java program in command prompt and then the java program is asking for password when the user types "password" its displaying on the screen
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There was a recent discussion on how to do this without Swing: https://coderanch.com/t/386342/java/java/Core-java-password-hiding

But the more important question is the one I raised in the second paragraph of my post: how will you store the encryption key?
 
Meet Gaurav
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is the Code,
System.out.print("Enter the Password");
String Password = br.readLine();

While running this asking for the password and user typed password on the command prompt its displaying on the screen

I want to hide that or simply show ****

Please advice
 
Meet Gaurav
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any possibility in Java 1.5.. Please advice
 
Meet Gaurav
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Even I tried this

With the right OS you can do this:

public static void echo(boolean on) {
try {
String[] cmd = {
"/bin/sh",
"-c",
"/bin/stty " + (on ? "echo" : "-echo") + " < /dev/tty"
};
Process p = Runtime.getRuntime().exec(cmd);
p.waitFor();
}
catch (IOException e) { }
catch (InterruptedException e) { }
}


Then use echo(false) to turn off echo, and echo(true) to turn it back
on again:


BufferedReader br = new BufferedReader(new InputStreamReader(System.in));


try {
echo(false);
System.out.print("enter password: ");
String pass = br.readLine();
System.out.println();
System.out.println("you entered: " + pass);
}
finally {
echo(true);
}
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you actually read the topic I linked to?

Also, please check your private messages.
[ October 14, 2008: Message edited by: Ulf Dittmer ]
 
Meet Gaurav
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sure will check my private message..

Is there any way to Turn off the Echo using java code...
 
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you read the link already? It mentions System.console() which can do just that.
 
I've read about this kind of thing at the checkout counter. That's where I met this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic