I myself have become more and more concerned about password security. So, I decided to write a little app that would generate random passwords for me. As for the volunteer part, I'm posting it here hoping that other interested parties will contribute their own password generators, so we can have a community collection to choose from.
Possible applications of all of this?
1) Online game development. Say you're creating an online game and players have to create an account with you to log on. Want to auto-generate random passwords for them? Well here you go.
2) If you're using wireless routers at home, you ought to have encryption keys on that connection, and you know it.
3) If you're like me, you're going through and changing all your important online passwords to strong random passwords because paranoia is fun.

Put it on a flash drive and generate passwords anytime you need one.
I am aware that there are apps already existing that will do this for you, but it's a fun, and really easy thing to do.
Unfortunately I don't currently have web space to post it, but it's so short that I'll just post the code instead.
A) The first block of code is the interface that you should implement if you want to create your own password generator.
B) The second block is an example implementation that I'm currently using to generate random passwords - good for tutorial work too.
C) The third block is an actual command-line utility you can compile use to generate the passwords, using the Base32Generator class I provided, and output to a file. It's easy to use and documented.
All 100% Java, and no UI stuff as of yet, so no quirky AWT/Swing problems to worry about.
Open for comments/contributions.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| package password.generators;
public interface PasswordGenerator {
public String getNextPassword(); public String getStrength(); public int getPasswordLength(); public void setPasswordLength(int length); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| package password.generators;
public class Base32Generator implements PasswordGenerator {
public static final int DEFAULT_LENGTH = 8; public static final char[] base32Digits = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5'}; private int numDigits; public Base32Generator() { this.numDigits = DEFAULT_LENGTH; } public String getNextPassword() { StringBuffer pwBuffer = new StringBuffer(); for (int i = 0; i < numDigits; i++) { int currDigit = (int) (Math.random() * base32Digits.length); pwBuffer.append(base32Digits[currDigit]); } return pwBuffer.toString(); } public String getStrength() { int bitStrength = 5*getPasswordLength(); return ("Equivalent to " + bitStrength + "-bit password."); } public int getPasswordLength() { return this.numDigits; } public void setPasswordLength(int length) { this.numDigits = length; }
} |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
| import java.io.*;
import password.generators.Base32Generator;
public class PWG { public static void main(String[] args) { int numDigits = 0; int numPasswords = 0; File outputFile = null; BufferedWriter out = null; try { numDigits = Integer.parseInt(args[0]); numPasswords = Integer.parseInt(args[1]); if (args.length == 3) { outputFile = new File(args[2]); out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile))); } if (args.length > 3) throw new Exception("Invalid number of arguments."); } catch (Exception ex) { printUsage(); System.exit(1); } System.out.println(); Base32Generator b32Gen = new Base32Generator(); b32Gen.setPasswordLength(numDigits); for (int j = 0; j < numPasswords; j++) { if (out != null) { try { String password = b32Gen.getNextPassword(); out.write(password, 0, password.length()); out.newLine(); } catch (IOException ioEx) { System.err.println("Cannot output passwords to file - an I/O error has occured."); System.exit(2); } } else { System.out.println(b32Gen.getNextPassword()); } } try { if (out != null) { out.flush(); out.close(); } } catch (IOException ioEx) { } System.out.println(b32Gen.getStrength()); System.out.println(); } public static void printUsage() { System.out.println(); System.out.println("PWG <digits> <passwords> [output]"); System.out.println(); System.out.println("digits The number of digits in each generated password."); System.out.println("passwords The number of passwords to generate."); System.out.println("output The filename where the passwords will be dumped."); System.out.println(); } } |