1 13 14 package org.ejbca.util.passgen; 15 import java.util.Random ; 16 17 24 public abstract class BasePasswordGenerator implements IPasswordGenerator{ 25 26 protected BasePasswordGenerator(char[] usedchars){ 27 28 this.usedchars = usedchars; 29 } 30 31 34 35 public String getNewPassword(int minlength, int maxlength){ 36 int difference = maxlength - minlength; 37 char[] password = null; 38 39 Random ran = new Random (); 40 41 int passlen = maxlength; 43 if(minlength != maxlength) 44 passlen = minlength + ran.nextInt(difference); 45 46 password = new char[passlen]; 47 for(int i=0; i < passlen; i++){ 48 password[i] = usedchars[ran.nextInt(usedchars.length)]; 49 } 50 51 return new String (password); 52 } 53 54 55 private final char[] usedchars; 56 } 57 | Popular Tags |