Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package ScheduleManager.pkg;
- import java.io.BufferedWriter;
- import java.io.File;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.swing.JOptionPane;
- public class createUserPass extends javax.swing.JFrame {
- File file;
- /**
- * Creates new form createUserPass
- */
- public createUserPass() {
- String path = "\\src\\Schedulemanager\\pkg\\info.txt";
- file = new File(path); //creates new File
- /* if (file.exists()) { //make a new file if it's not already existent
- logIn loginPage = new logIn();
- loginPage.setVisible(true);
- loginPage.setAlwaysOnTop(true);
- this.dispose();
- this.setVisible(false);
- } else {
- file.createNewFile(); //creates the new file
- } */
- initComponents();
- }
- /**
- * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of this method is always regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- jLabel1 = new javax.swing.JLabel();
- jLabel2 = new javax.swing.JLabel();
- jLabel3 = new javax.swing.JLabel();
- userNameField = new javax.swing.JTextField();
- passwordField = new javax.swing.JTextField();
- jLabel4 = new javax.swing.JLabel();
- securityAnswer = new javax.swing.JTextField();
- submitButton = new javax.swing.JButton();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- jLabel1.setText("Please set your username, password and security question.");
- jLabel2.setText("username:");
- jLabel3.setText("password:");
- jLabel4.setText("security question: what was your favourite class in college?");
- submitButton.setText("submit");
- submitButton.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- submitButtonActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(30, 30, 30)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel3)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(passwordField))
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel2)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(userNameField))))
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addGap(0, 27, Short.MAX_VALUE)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 391, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(securityAnswer, javax.swing.GroupLayout.PREFERRED_SIZE, 378, javax.swing.GroupLayout.PREFERRED_SIZE))))
- .addContainerGap())
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addGap(0, 0, Short.MAX_VALUE)
- .addComponent(submitButton)
- .addGap(159, 159, 159))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel2)
- .addComponent(userNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(24, 24, 24)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel3)
- .addComponent(passwordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(18, 18, 18)
- .addComponent(jLabel4)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(securityAnswer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(submitButton)
- .addContainerGap())
- );
- pack();
- }// </editor-fold>
- private void submitButtonActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- String username = userNameField.getText();
- String password = passwordField.getText();
- String answer = securityAnswer.getText();
- if (!userNameField.getText().equals("") && !passwordField.getText().equals("")
- && !securityAnswer.getText().equals("")) {
- try {
- String encryptedUsername = encrypt(username);
- String encryptedPassword = encrypt(password);
- String encryptedAnswer = encrypt(answer);
- String content = encryptedUsername + "\n" + encryptedPassword + "\n" + encryptedAnswer;
- file.createNewFile(); //creates the new file
- FileWriter fw = new FileWriter(file.getAbsoluteFile());
- BufferedWriter bw = new BufferedWriter(fw);
- bw.write(content);
- bw.close();
- logIn loginPage = new logIn();
- loginPage.setVisible(true);
- loginPage.setAlwaysOnTop(true);
- this.dispose();
- } catch (Exception e) {
- System.out.println(e);
- }
- } else {
- JOptionPane.showMessageDialog(null,
- "All fields must be filled.",
- "ERROR",
- JOptionPane.WARNING_MESSAGE);
- }
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(createUserPass.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(createUserPass.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(createUserPass.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(createUserPass.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- //try {
- new createUserPass().setVisible(true);
- /*} catch (IOException ex) {
- Logger.getLogger(createUserPass.class.getName()).log(Level.SEVERE, null, ex);
- } */
- }
- });
- }
- public static String encrypt(String x) { //caesar cipher shifts letters by 3 places
- char[] message = x.toCharArray();
- for (int i = 0; i < message.length; i++) {
- char character = message[i];
- character = (char) (character + 3);
- if (character > 'z') {
- character = (char) (character - 26);
- } else if (character < 'a') {
- character = (char) (character + 26);
- }
- message[i] = character;
- }
- String output = new String(message);
- System.out.println("from " + x + " to " + output);
- return output;
- }
- // Variables declaration - do not modify
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JLabel jLabel3;
- private javax.swing.JLabel jLabel4;
- private javax.swing.JTextField passwordField;
- private javax.swing.JTextField securityAnswer;
- private javax.swing.JButton submitButton;
- private javax.swing.JTextField userNameField;
- // End of variables declaration
- }
Add Comment
Please, Sign In to add comment