You are viewing our Forum Archives. To view or take place in current topics click here.
AccountHandler [Java]
Posted:
AccountHandler [Java]Posted:
Status: Offline
Joined: May 08, 201113Year Member
Posts: 699
Reputation Power: 28
Status: Offline
Joined: May 08, 201113Year Member
Posts: 699
Reputation Power: 28
import java.io.Console;public class LoginTester {
private static enum Credentials {
JACK("Jack", "abc123"), JOE("Joe", "noob"), Hiimmanly("Hiimmanly", "sexy"), MOPAR("Mopar", "isthebest");
private final String username;
private final String password;
Credentials(String username, String password) {
this.username = username;
this.password = password;
}
String username() {
return username;
}
String password() {
return password;
}
}
private static boolean validate(String username, String password) {
for (Credentials credentials : Credentials.values()) {
if (credentials.username().equals(username) && credentials.password().equals(password)) {
return true;
}
}
return false;
}
public static void main(String[] argv) {
final int MAX_ATTEMPTS = 10;
int attempts = 0;
Console console = System.console();
if (console == null) {
System.err.println("please use from a console!");
} else {
while (attempts < MAX_ATTEMPTS) {
String username = console.readLine("username: ");
String password = String.valueOf(console.readPasswor
("password: "));
if (validate(username, password)) {
System.out.println("success");
break;
} else {
++attempts;
}
}
}
}
}
Checks to tell if you're using the correct Username and Password. Any improvements?
Also i'm pretty newbie at Java and am trying to learn, so don't be flammin'!
#2. Posted:
Status: Offline
Joined: Sep 06, 201013Year Member
Posts: 1,069
Reputation Power: 47
Status: Offline
Joined: Sep 06, 201013Year Member
Posts: 1,069
Reputation Power: 47
For the practice, you should make a version of it that connects to a database to get the user info, and instead of storing their password, you should md5 hash it.
- 0useful
- 0not useful
#3. Posted:
Status: Offline
Joined: May 08, 201113Year Member
Posts: 699
Reputation Power: 28
Status: Offline
Joined: May 08, 201113Year Member
Posts: 699
Reputation Power: 28
M0D1F13D wrote For the practice, you should make a version of it that connects to a database to get the user info, and instead of storing their password, you should md5 hash it.
I posted this on another forum and they also said I should md5 hash it, and I cba making it connect to anything right now.
- 0useful
- 0not useful
You are viewing our Forum Archives. To view or take place in current topics click here.