Login dialog with ecncrypted password
Hi there,
I developed a Java application that has an initial JDialog
frame where the user enters his/her name and password.
Then I access a database and check if the password is
the right one, enabling or not the user to continue
loading the app.
Since I'm new to security and stuff, I was wondering
if anybody could send to me some code showing
how I can :
1) Encrypt the password from the JPasswordField
2) Decrypt the password that is stored on the
database
3) Check if they are the same.
What should I download from Sun's website ?
What are the steps to implement what I want ?
Of course I'll be using the same encryption method
to build a frame where the user stores his/her own
password, right ?
If possible, please send the code to wmaxsen@yahoo.com
Thanks a lot
[909 byte] By [
maxsen] at [2007-9-26 6:02:23]

Hi I am giving you the code with which you can do basic encryption and decryption. You can add encryption code in the class where you are displaying password dialog and send it then you decrypt and save it in data base.
One suggestion for you.
It will be a good idea to store password in encrypted form in the database. when you get username and password from log in encrypt it and compare both password in encrypted form. Never decrypt it.
code is not nicely written but works. So,hope it might solve your problem.
Enjoy it :)
Bhavesh
import sun.misc.*;
public class TestEncrypt{
static String temp = "pass";
BASE64Encoder encoder;
BASE64Decoder decoder;
String encodedStr;
byte [] testPass;
public TestEncrypt(){
encoder= new BASE64Encoder();
decoder = new BASE64Decoder();
try{
testPass = temp.getBytes();
encodedStr = encoder.encodeBuffer(testPass);
System.out.println(new String(encoder.encodeBuffer(testPass)));
if(temp.equals(new String(decoder.decodeBuffer(encodedStr))))
System.out.println("HI BOTH are same");
else
System.out.println("BOth are no same");
}catch(Exception ex){ex.printStackTrace();}
}
public static void main(String args[]){
new TestEncrypt();
}
}