Java Random randomPassword()

Here you can find the source of randomPassword()

Description

Generate a random password, used when a password validation fails to ensure that the user doesn't get saved with some sort of invalid (and thus insecure) password.

License

Open Source License

Return

String

Declaration

public static String randomPassword() 

Method Source Code

//package com.java2s;

import java.util.*;

public class Main {
    /** Module name */
    private static final String MODULE_NAME = "FusionUtils.";

    /**//from w w  w.j a v a  2 s .co  m
     * Generate a random password, used when a password validation fails to ensure that the user doesn't get saved with
     * some sort of invalid (and thus insecure) password. Also used to initialize passwords.
     *
     * @return String 
     */
    public static String randomPassword() {
        String methodName = MODULE_NAME + "randomPassword()";
        String retval = "";
        char[] pwd = new char[12];

        Random randomGuy = new Random();

        //We only want ASCII values 40-126
        for (int i = 0; i < pwd.length; i++) {
            pwd[i] = (char) (randomGuy.nextInt(86) + 40);
        }

        retval = new String(pwd);

        //Logger.log( methodName + " generated: " + retval, Logger.INFO );

        return retval;
    }
}

Related

  1. randomLetter()
  2. randomList(Collection collection)
  3. randomMember(Collection collection)
  4. randomNanoTime()
  5. randomNick()
  6. randomPermutation(int size)
  7. randomPermutations(int[] tab, Random r)
  8. randomPermute(List l, Random rand)
  9. randomProbability(double probability)