001package co.codewizards.cloudstore.rest.server.auth;
002
003import java.security.SecureRandom;
004
005public final class PasswordUtil {
006        private PasswordUtil() { }
007
008        private static SecureRandom random = new SecureRandom();
009
010        private static final char[] PASSWORD_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-*/=.!?,;#$()[]{}~".toCharArray();
011
012        public static char[] createRandomPassword(int length) {
013                if (length < 8)
014                        throw new IllegalArgumentException("length < 8");
015
016                char[] result = new char[length];
017
018                for (int i = 0; i < result.length; ++i)
019                        result[i] = PASSWORD_CHARS[random.nextInt(PASSWORD_CHARS.length)];
020
021                return result;
022        }
023
024}