Ein kleines Tool, dass ich eben geschrieben habe um schnell sichere Passwörter zu generieren.
Mit den Checkboxen können die Zeichen ausgewählt werden. Die Länge kann außerdem geändert werden. Bei jeder Änderung wird ein neues Passwort generiert und automatisch in der Zwischenablage gespeichert, um schneller ein Passwort zu haben. Aus jedem Zeichenset kommt im Passwort mindestens ein Zeichen vor.
Download von PasswortGenerator.jar
Quellcode:
package de.zuim.passwordGen; import java.awt.Toolkit; import java.awt.datatransfer.StringSelection; import java.security.SecureRandom; public class PasswordGen { private int len; private String[] charParts; private boolean[] charAct; public PasswordGen() { charParts = new String[] {"abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "0123456789", "%&$_+-*/=", "()?.,#'\"", " ", "°€@[]{}"}; charAct = new boolean[] {true, true, true, true, false, false, false}; len = 10; } public String gen() { String pw = ""; String charList = getChars(); for(int i = 0; i < len; i++) { SecureRandom sr = new SecureRandom(); pw += charList.charAt(sr.nextInt(charList.length())); } //one of every type for(int i = 0; getCharActNum() <= len && i < charParts.length; i++) { if(charAct[i]) { boolean contains = false; for(char c : charParts[i].toCharArray()) { if(pw.contains(""+c)) contains = true; } if(!contains) return gen(); } } Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(pw), null); return pw; } public String getChars() { String charList = ""; for(int i = 0; i < charParts.length; i++) { if(charAct[i]) charList += charParts[i]; } return charList; } public int getLen() { return len; } public void setLen(int len) { this.len = len; } public String[] getCharParts() { return charParts; } public boolean[] getCharAct() { return charAct; } public int getCharActNum() { int num = 0; for(boolean c : charAct) if(c) num++; return num; } }
package de.zuim.passwordGen; import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.JTextField; import javax.swing.JButton; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.awt.FlowLayout; import javax.swing.JCheckBox; import javax.swing.SpringLayout; import java.awt.Dimension; import javax.swing.JSpinner; import javax.swing.JLabel; import javax.swing.SpinnerNumberModel; public class Frame extends JFrame { private static final long serialVersionUID = 796818925968037119L; private JPanel contentPane; private JTextField textField; private PasswordGen gen; private JPanel panel; private JSpinner spinner; private JButton btnNewButton; /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { Frame frame = new Frame(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the frame. */ public Frame() { setMinimumSize(new Dimension(400, 200)); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLocationRelativeTo(null); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); btnNewButton = new JButton("Generieren"); SpringLayout sl_contentPane = new SpringLayout(); sl_contentPane.putConstraint(SpringLayout.NORTH, btnNewButton, 10, SpringLayout.NORTH, contentPane); sl_contentPane.putConstraint(SpringLayout.WEST, btnNewButton, -200, SpringLayout.EAST, contentPane); sl_contentPane.putConstraint(SpringLayout.EAST, btnNewButton, -10, SpringLayout.EAST, contentPane); contentPane.setLayout(sl_contentPane); textField = new JTextField(); sl_contentPane.putConstraint(SpringLayout.NORTH, textField, 11, SpringLayout.NORTH, contentPane); sl_contentPane.putConstraint(SpringLayout.WEST, textField, 9, SpringLayout.WEST, contentPane); sl_contentPane.putConstraint(SpringLayout.EAST, textField, -10, SpringLayout.WEST, btnNewButton); contentPane.add(textField); textField.setColumns(10); contentPane.add(btnNewButton); panel = new JPanel(); sl_contentPane.putConstraint(SpringLayout.NORTH, panel, 32, SpringLayout.NORTH, contentPane); sl_contentPane.putConstraint(SpringLayout.WEST, panel, 9, SpringLayout.WEST, contentPane); sl_contentPane.putConstraint(SpringLayout.SOUTH, panel, -15, SpringLayout.SOUTH, contentPane); sl_contentPane.putConstraint(SpringLayout.EAST, panel, -10, SpringLayout.EAST, contentPane); contentPane.add(panel); FlowLayout fl_panel = new FlowLayout(FlowLayout.LEFT, 5, 5); fl_panel.setAlignOnBaseline(true); panel.setLayout(fl_panel); JLabel lblLnge = new JLabel("L\u00E4nge"); panel.add(lblLnge); spinner = new JSpinner(); spinner.setPreferredSize(new Dimension(40, 20)); panel.add(spinner); init(); } public void init() { gen = new PasswordGen(); btnNewButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { genPass(); } }); spinner.setModel(new SpinnerNumberModel(new Integer(gen.getLen()), new Integer(1), null, new Integer(1))); spinner.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { gen.setLen((int) spinner.getValue()); genPass(); } }); for(int i = 0; i < gen.getCharParts().length; i++) { final JCheckBox box = new JCheckBox(gen.getCharParts()[i], gen.getCharAct()[i]); panel.add(box); final int pos = i; box.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { gen.getCharAct()[pos] = box.isSelected(); genPass(); } }); } genPass(); } public void genPass() { textField.setText(gen.gen()); } }