generate Password - Java Security

Java examples for Security:Password

Description

generate Password

Demo Code


//package com.java2s;
import java.util.Random;

public class Main {
    public static void main(String[] argv) throws Exception {
        System.out.println(generatePass());
    }//from www  . j  a v  a  2  s. com

    public static String generatePass() {
        StringBuilder sb = new StringBuilder();
        char c;
        Random rnd = new Random();
        for (int i = 0; i < 12; i++) {
            c = (char) ((rnd.nextInt(128 - 32)) + 32);
            sb.append(c);
        }
        return sb.toString();
    }
}

Related Tutorials