Android Password Create generateRandomPassword(int length)

Here you can find the source of generateRandomPassword(int length)

Description

generate Random Password

License

Open Source License

Declaration

public static String generateRandomPassword(int length) 

Method Source Code

//package com.java2s;
import java.security.SecureRandom;

import java.util.Random;

public class Main {
    private static final Random RANDOM = new SecureRandom();
    public static final char[] RANDOM_LETTERS = new char[] { 'a', 'b', 'c',
            'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
            'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A',
            'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
            'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y',
            'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '+',
            '-', '@' };

    public static String generateRandomPassword(int length) {

        StringBuffer sb = new StringBuffer(length);
        for (int i = 0; i < length; i++) {
            int index = (int) (RANDOM.nextDouble() * RANDOM_LETTERS.length);
            sb.append(RANDOM_LETTERS[index]);
        }/*  w w  w  .jav a2  s  .c  o m*/
        return sb.toString();
    }
}

Related

  1. generatePassword()
  2. generateUsername()