package com.sequenceiq.cloudbreak.util;

import org.apache.commons.lang3.RandomStringUtils;

public class FreeIpaPasswordUtil {

    private static final int PWD_PART_LENGTH = 8;

    private static final String SPECIAL_CHARS = "?!.@-*_+";

    private static final int UPPER_CASE_LETTERS_START = 65;

    private static final int UPPER_CASE_LETTERS_END = 90;

    private static final int LOWER_CASE_LETTERS_START = 97;

    private static final int LOWER_CASE_LETTERS_END = 122;

    private static final int PASSWORD_LENGTH = 32;

    private FreeIpaPasswordUtil() {
    }

    public static String generatePassword() {
        String upperCaseLetters = RandomStringUtils.random(PWD_PART_LENGTH, UPPER_CASE_LETTERS_START, UPPER_CASE_LETTERS_END, true, true);
        String lowerCaseLetters = RandomStringUtils.random(PWD_PART_LENGTH, LOWER_CASE_LETTERS_START, LOWER_CASE_LETTERS_END, true, true);
        String numbers = RandomStringUtils.randomNumeric(PWD_PART_LENGTH);
        String raw = upperCaseLetters.concat(lowerCaseLetters).concat(numbers).concat(SPECIAL_CHARS);
        return RandomStringUtils.random(PASSWORD_LENGTH, raw);
    }
}

@@ -34,16 +34,95 @@
 .util;%0A%0A
+import java.util.Arrays;%0Aimport java.util.Collections;%0Aimport java.util.List;%0A%0A
 import o
@@ -231,27 +231,29 @@
 al int PWD_P
-ART
+REFIX
 _LENGTH = 8;
@@ -254,9 +254,9 @@
 H = 
-8
+2
 ;%0A%0A 
@@ -283,102 +283,31 @@
 nal 
-String SPECIAL_CHARS = %22?!.@-*_+%22;%0A%0A    private static final int UPPER_CASE_LETTERS_START = 65
+int PWD_PART_LENGTH = 8
 ;%0A%0A 
@@ -334,212 +334,38 @@
 nal 
-int UPPER_CASE_LETTERS_END = 90;%0A%0A    private static final int LOWER_CASE_LETTERS_START = 97;%0A%0A    private static final int LOWER_CASE_LETTERS_END = 122;%0A%0A    private static final int PASSWORD_LENGTH = 32
+String SPECIAL_CHARS = %22?.-_+%22
 ;%0A%0A 
@@ -502,32 +502,42 @@
 ringUtils.random
+Alphabetic
 (PWD_PART_LENGTH
@@ -540,70 +540,22 @@
 NGTH
-, UPPER_CASE_LETTERS_START, UPPER_CASE_LETTERS_END, true, true
+).toUpperCase(
 );%0A 
@@ -611,16 +611,26 @@
 s.random
+Alphabetic
 (PWD_PAR
@@ -641,70 +641,104 @@
 NGTH
-, LOWER_CASE_LETTERS_START, LOWER_CASE_LETTERS_END, true, true
+).toLowerCase();%0A        String pwdPrefix = RandomStringUtils.randomAlphabetic(PWD_PREFIX_LENGTH
 );%0A 
@@ -925,60 +925,140 @@
     
-return RandomStringUtils.random(PASSWORD_LENGTH, raw
+List%3CString%3E list = Arrays.asList(raw.split(%22%22));%0A        Collections.shuffle(list);%0A        return pwdPrefix.concat(list.toString()
 );%0A 

create prefix for pwd