Sample code for 30+ languages & platforms
Java

Generating Random Password

See more PRNG Examples

Demonstrates how to generate random passwords.

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.Prng;

public class ChilkatExample {

    public static void main(String[] args) {
        boolean success = false;

        // This example assumes the Chilkat API to have been previously unlocked.
        // See Global Unlock Sample for sample code.

        success = false;

        Prng fortuna = new Prng();

        // Set this equal to true if the generated password must include at least one digit (0-9)
        boolean bDigit = true;

        // Set this equal to true if the generated password must include both uppercase and lowercase chars.
        boolean bUpperAndLower = true;

        // The generated password must contain one of the following non-alphanumeric chars.
        String otherChars = "@#$%*";

        // Exclude chars that appear similar to others:
        String excludeChars = "iIlLoO0";

        // Generate 8-character passwords:
        for (int i = 1; i <= 10; i++) {
            System.out.println(fortuna.randomPassword(8, bDigit, bUpperAndLower, otherChars, excludeChars));
        }
    }
}