001 package org.hackystat.sensorbase.resource.users; 002 003 import java.util.Random; 004 005 /** 006 * Provides a static function for generating new, unique passwords. 007 * Package private because only UserManager should be interacting with this class. 008 * 009 * @author Philip M. Johnson 010 */ 011 class PasswordGenerator { 012 /** 013 * Eliminate letters/numbers that are easily confused, such as 0, O, l, 1, I, etc. 014 * Do NOT include the '@' char, because that is used to distinguish dirkeys from email addresses. 015 */ 016 private static String[] charset = { 017 "A", "B", "C", "D", "E", "F", "G", 018 "H", "J", "K", "L", "M", "N", 019 "P", "Q", "R", "S", "T", "U", 020 "V", "W", "X", "Y", "Z", 021 "a", "b", "c", "d", "e", "f", "g", 022 "h", "i", "j", "k", "m", "n", "p", 023 "q", "r", "s", "t", "u", "v", "w", 024 "x", "y", "z", 025 "2", "3", "4", "5", "6", "7", "8", "9"}; 026 027 /** Length of the password. */ 028 private static final int PASSWORD_LENGTH = 12; 029 030 /** 031 * Creates and returns a new randomly generated password. 032 * 033 * @return The random string. 034 */ 035 public static String make() { 036 Random generator = new Random(System.currentTimeMillis()); 037 StringBuffer password = null; 038 password = new StringBuffer(PasswordGenerator.PASSWORD_LENGTH); 039 for (int i = 0; i < PasswordGenerator.PASSWORD_LENGTH; i++) { 040 password.append(charset[generator.nextInt(charset.length)]); 041 } 042 return password.toString(); 043 } 044 045 /** Ensure that no one can create an instance of this class. */ 046 private PasswordGenerator() { 047 } 048 049 }