03-17-2012, 12:24 AM
(03-17-2012, 12:15 AM)aHardyX Wrote: Ok. Here's what you want:
Code:import java.io.*;
class PasswordChecker
{
private String $PasswordStored="Password"; //This is the stored Password.
private void inputPassword()
{
/*
This method accepts the password from the user and
checks whether it is correct.
*/
try
{
String $PasswordEntered = new String();
int varCounter = 0;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while (varCounter<3)
{
System.out.println("Enter the Password:");
$PasswordEntered = br.readLine();
if ($PasswordEntered.equals($PasswordStored))
{
System.out.println("Welcome");
System.exit(0);
}
else
{
System.out.println("The password you typed is incorrect.");
}
varCounter++;
}
System.out.println("Access Denied");
System.exit(0);
}
catch(Exception error)
{
System.out.println("Error: "+error.toString());
}
}
public static void main(String args[])
{
try
{
PasswordChecker PC = new PasswordChecker();
PC.inputPassword();
}
catch(Exception error)
{
System.out.println("Error: "+error.toString());
}
}
}
Thanks u saved my ass, I edited this a bit, but thanks so much.