Java Password Generate generatePassword()

Here you can find the source of generatePassword()

Description

generate Password

License

Apache License

Declaration

public static String generatePassword() throws Exception 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.Random;

public class Main {
    public static String generatePassword() throws Exception {
        try {/*w  w w  .ja va2 s .c o m*/
            char[] charArray = "abcdefghijklmnopqrstuvwxyz".toCharArray();
            StringBuilder stringBuilder = new StringBuilder();
            Random random = new Random();
            for (int i = 0; i < 10; i++) {
                char c = charArray[random.nextInt(charArray.length)];
                stringBuilder.append(c);
            }
            String randomPassword = stringBuilder.toString();
            return randomPassword;
        } catch (Exception e) {
            throw new Exception("Password generation failed!");
        }
    }
}

Related

  1. generatePassword()
  2. generatePassword()
  3. generatePassword()
  4. generatePassword()
  5. generatePassword()
  6. generatePassword(int lenght)
  7. generatePassword(int length)
  8. generatePassword(int length)
  9. generatePassword(int length, boolean special)