11-07-2009, 09:14 AM
Well it seems the other programmers in some other sections have been creating password generators in different languages, so I thought I would take a swing at it and make something simple out of it. I may improve it or work off some of your ideas.
Anyhow, its a simple GUI that has 3 textfields, which creates/writes to a Passwords.txt file. I may make it load in XML just for the fun of it later.
http://uppit.com/v/845HLDTA
Virus scan if you wish, but its clean.
Thanks.
Src
As you can see, I used NetBeans to create the GUI, since I can never be bothered to do it myself.. >.>
Anyhow, its a simple GUI that has 3 textfields, which creates/writes to a Passwords.txt file. I may make it load in XML just for the fun of it later.
http://uppit.com/v/845HLDTA
Virus scan if you wish, but its clean.
Thanks.
Src
Code:
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Random;
/*
* GUI.java
*
* Created on 6-Nov-2009, 9:29:37 PM
*
* @author Anthony Calandra
*/
public class PasswordGen extends javax.swing.JFrame {
public PasswordGen() {
initComponents();
}
public static void main(String[] args) {
new PasswordGen().setVisible(true);
}
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
jTextField2 = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
jTextField3 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jTextField4 = new javax.swing.JTextField();
jButton4 = new javax.swing.JButton();
jLabel7 = new javax.swing.JLabel();
jTextField5 = new javax.swing.JTextField();
jButton5 = new javax.swing.JButton();
jButton6 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14));
jLabel1.setText("Password Utility Panel");
jLabel2.setText("Desired Username:");
jLabel3.setText("Desired Password:");
jLabel4.setText("Login for:");
jTextField3.setText("example: Google sign-in.");
jButton1.setText("Save to Text File");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton3.setText("Close");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jButton2.setText("Clear Fields");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jLabel5.setFont(new java.awt.Font("Tahoma", 1, 14));
jLabel5.setText("Password (Number) Randomizer");
jLabel6.setText("Enter a password:");
jButton4.setText("Randomize");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});
jLabel7.setText("Randomized Password:");
jTextField5.setEditable(false);
jButton5.setText("Clear Randomizer");
jButton5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton5ActionPerformed(evt);
}
});
jButton6.setText("Get Randomized Password");
jButton6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton6ActionPerformed(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()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextField3, javax.swing.GroupLayout.DEFAULT_SIZE, 184, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 141, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton1)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton6))
.addGap(25, 25, 25))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel6)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(10, 10, 10)
.addComponent(jButton4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton5))
.addGroup(layout.createSequentialGroup()
.addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel7)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextField5, javax.swing.GroupLayout.DEFAULT_SIZE, 115, Short.MAX_VALUE)))
.addContainerGap())))
.addGroup(layout.createSequentialGroup()
.addGap(138, 138, 138)
.addComponent(jLabel1)
.addContainerGap(157, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGap(133, 133, 133)
.addComponent(jLabel5)
.addContainerGap(88, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGap(184, 184, 184)
.addComponent(jButton3)
.addContainerGap(203, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton6))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton2))
.addGap(15, 15, 15)
.addComponent(jLabel5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel6)
.addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel7)
.addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton4)
.addComponent(jButton5))
.addGap(18, 18, 18)
.addComponent(jButton3)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}
Random randomGen = new Random();
private String randomizeInt() {
int toInt = Integer.parseInt(jTextField4.getText());
int randomIndex = randomGen.nextInt(toInt);
String randomString = Integer.toString(randomIndex);
return randomString;
}
/* private char randomizeChar() {
String randomString = jTextField4.getText();
char toChar = (char) randomString.lastIndexOf(randomString.length());
return (char) (randomGen.nextInt(toChar));
} */
private void createFile() {
try {
File f = new File("Passwords.txt");
f.createNewFile();
BufferedWriter bw = new BufferedWriter(new FileWriter(f));
bw.write("--- " + jTextField1.getText() + " Login information ---");
bw.newLine();
bw.write("Username: " + jTextField2.getText() + "");
bw.newLine();
bw.write("Password: " + jTextField3.getText() + "");
bw.newLine();
bw.newLine();
bw.close();
} catch(IOException ioe) {
ioe.printStackTrace();
}
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
createFile();
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField5.setText(randomizeInt());
}
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField5.setText("");
}
private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField2.setText(jTextField5.getText());
}
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JButton jButton5;
private javax.swing.JButton jButton6;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
private javax.swing.JTextField jTextField4;
private javax.swing.JTextField jTextField5;
}
As you can see, I used NetBeans to create the GUI, since I can never be bothered to do it myself.. >.>