Here you can find the source of generatePassword(int length)
public static String generatePassword(int length)
//package com.java2s; //License from project: Apache License import java.util.Random; public class Main { private static final String DIGITS = "0123456789"; private static final String LETTERS = "abcdefghijklmnopqrstuvwxyz"; private static final String SPECIALS = "!@#$%^&*()_+-=,.?/;:{}[]|`~<>'"; public static String generatePassword(int length) { if (length <= 0) { return ""; }/* ww w . ja va 2 s . c o m*/ Random random = new Random(); StringBuilder sb = new StringBuilder(); String exCludeChar = "'<>&"; String[] charSets = { DIGITS, LETTERS, SPECIALS }; for (int i = 0; i < length; i++) { int r = random.nextInt(charSets.length); String charSet = charSets[r]; r = random.nextInt(charSet.length()); char c = charSet.charAt(r); if (exCludeChar.contains(String.valueOf(c))) { // exclude i--; continue; } sb.append(charSet.charAt(r)); } return sb.toString(); } }