Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void jButtonRegisterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRegisterActionPerformed
- // TODO add your handling code here:
- String firstName = jTextFirstName.getText();
- String lastName = jTextLastName.getText();
- String username = jTextUsername.getText();
- String password = new String(jPassword.getPassword());
- try{
- BufferedReader reader = new BufferedReader(new FileReader("/Users/pantvad/Downloads/Security_Project3/src/main/java/users.txt"));
- boolean check = false;
- for(String line;(line = reader.readLine()) != null;) {
- int i = line.indexOf('-');
- String testString = line.substring(0, i);
- if (testString.equals(username)) {
- check = true;
- break;
- }
- }
- if(!check) {
- StringBuilder usersInfo = new StringBuilder(username);
- usersInfo.append("-");
- usersInfo.append(firstName);
- usersInfo.append("-");
- usersInfo.append(lastName);
- usersInfo.append("-");
- usersInfo.append(password.hashCode());
- String last = usersInfo.toString();
- System.out.println(last);
- PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("/Users/pantvad/Downloads/Security_Project3/src/main/java/users.txt", true)));
- out.println(last);
- out.close();
- JOptionPane.showMessageDialog(new JFrame(), "Register Successfull");
- }
- else{
- JOptionPane.showMessageDialog(new JFrame(), "Username already exists");
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- //System.out.println(firstName + lastName + username + password);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement