Skip to content

Instantly share code, notes, and snippets.

@NathanJang
Last active January 21, 2016 01:19
Show Gist options
  • Save NathanJang/f271bd3a8cc9fbdfa35b to your computer and use it in GitHub Desktop.
Save NathanJang/f271bd3a8cc9fbdfa35b to your computer and use it in GitHub Desktop.
Bad code for APCS
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
public class ShittyPasswordApp
{
public static void main(String[] args) {
new ShittyPasswordApp().run();
}
private ShittyPasswordApp() {}
private void run() {
for (int i = 0; i < ShittyPasswordApp.numberOfAllowedTries; i++) {
String userInput = this.promptForPassword();
if (userInput != null && userInput.equals(ShittyPasswordApp.halfArsedPasswordStoredInPlainText)) {
System.out.println("Password is correct.");
return;
}
System.out.println("Password is incorrect.");
}
System.out.println("You have used up your tries.");
}
private String promptForPassword() {
JPasswordField passwordField = new JPasswordField(ShittyPasswordApp.halfArsedPasswordStoredInPlainText.length());
int option = JOptionPane.showConfirmDialog(null, passwordField, "Enter Password", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
if (option == JOptionPane.OK_OPTION) {
return new String(passwordField.getPassword());
} else {
return null;
}
}
private static String halfArsedPasswordStoredInPlainText = "\u0075\u0077\u0030\u0074\u006d\u0038";
private static int numberOfAllowedTries = 3;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment