Java code For Passwords

Hi, I'm new to this forum and to java programming, I am takin a course on java in school and I was wondering if anyone could provide me with a very simple code that would allow me to add a password to my java code so when someone trys to run it they need the password. It just needs to be very basic 1 user name 1 password.

Im sorry if this has been asked and answered, and if this is in the wrong place, plz feel free to move it. Thx in advanced

[460 byte] By [Ghost_Rider_1a] at [2007-10-2 0:29:01]
# 1

Try this simple program.

import java.io.*;

class TestPassword {

public static void main(String[] args) throws Exception {

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

System.out.println ("Enter your username");

String user = br.readLine ();

System.out.println ("Enter your password");

String password = br.readLine ();

if (!"scott".equals (user) && "tiger".equals (password)) {

System.out.println ("Sorry, username unknown or password wrong");

System.exit (1);

}

System.out.println ("Hello, world!");

}

}

Sample run:

C>java -cp . TestPassword

Enter your username

scott

Enter your password

tiger

Hello, world!

edsonwa at 2007-7-15 16:43:29 > top of Java-index,Security,Cryptography...
# 2

Thank you for the Java code, it works, the only problem is I can put in any user name and password and the text will come up, is this suppose to be? or did i forget to program something? also is there any way i could make it look like the way that you would log onto this site? instead of just putting it in, in the console

Ghost_Rider_1a at 2007-7-15 16:43:29 > top of Java-index,Security,Cryptography...
# 3
If you want the input to be hidden, use JPasswordField.R. Hollenstein
robinhollensteina at 2007-7-15 16:43:29 > top of Java-index,Security,Cryptography...
# 4
Its a good coding for enter user name and passwordaccording to ur codingif the userr enter wrong password and the user anme still the same screen and mesage is appear "Hello World"
itusaa at 2007-7-15 16:43:29 > top of Java-index,Security,Cryptography...
# 5
He forgot to type a ! if that really matters to you.
RichardTheLionHearteda at 2007-7-15 16:43:29 > top of Java-index,Security,Cryptography...