Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ublic boolean passwordCheck() {
- if (!tPassword1.getText().equals(tPassword2.getText())) {
- JOptionPane.showMessageDialog(Signup.this, "Passwords do not match try again.", "Error",
- JOptionPane.ERROR_MESSAGE);
- return false;
- }
- return true;
- }
- private boolean readLogin() {
- try {
- BufferedReader getData = new BufferedReader(new FileReader(new File("UPW.txt")));
- String logininfo = getData.readLine();
- while (logininfo != null) {
- String[] pass = logininfo.split(",");
- if (pass[0].equals(tUsername.getText())) {
- JOptionPane.showMessageDialog(Signup.this, "Username is already taken. Please try again.", "Error",
- JOptionPane.ERROR_MESSAGE);
- return false;
- }
- logininfo = getData.readLine();
- }
- getData.close();
- } catch (IOException e) {
- System.out.println(e);
- System.exit(0);
- }
- return true;
- }
- private class ListenForButton implements ActionListener {
- public void actionPerformed(ActionEvent d) {
- if (d.getSource() == signUp) {
- if (readLogin() && passwordCheck()) {
- new writer(tUsername.getText(), tPassword1.getText(), tPassword2.getText());
- JOptionPane.showMessageDialog(Signup.this, "You have successfully signed up.", "",
- JOptionPane.PLAIN_MESSAGE);
- dispose();
- }
- } else if (d.getSource() == cancel) {
- dispose();
- }
- }
- }
- public class writer {
- private String username;
- private String password;
- public writer(String username, String password, String confirm) {
- this.username = username;
- this.password = password;
- try {
- PrintWriter fileOut = new PrintWriter(new BufferedWriter(new FileWriter("UPW.txt", true)));
- fileOut.println(this.username + "," + this.password);
- fileOut.close();
- } catch (IOException e) {
- System.out.println("could not find and/or open file");
- System.out.println(e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement