java-faker icon indicating copy to clipboard operation
java-faker copied to clipboard

Add ability to init special characters

Open arturmkr opened this issue 4 years ago • 3 comments

Problem: Currently, special characters are hardcoded.

Solution: It would be great if it would be possible to init / set / reload special characters.

Code, where special characters are used:

    public String password(int minimumLength, int maximumLength, boolean includeUppercase, boolean includeSpecial, boolean includeDigit) {
        if (includeSpecial) {
            char[] password = faker.lorem().characters(minimumLength, maximumLength, includeUppercase, includeDigit).toCharArray();
            char[] special = new char[]{'!', '@', '#', '$', '%', '^', '&', '*'};
            for (int i = 0; i < faker.random().nextInt(minimumLength); i++) {
                password[faker.random().nextInt(password.length)] = special[faker.random().nextInt(special.length)];
            }
            return new String(password);
        } else {
            return faker.lorem().characters(minimumLength, maximumLength, includeUppercase, includeDigit);
        }
    }

arturmkr avatar Nov 02 '20 14:11 arturmkr

Do you mean that it should provide an interface to let user set the desired special letters?

Zhang-Muyang avatar Apr 17 '21 08:04 Zhang-Muyang

I would be happy to volunteer to work on this feature in Oct/Nov for an academic project.

leoncho avatar Oct 20 '21 23:10 leoncho

Pull Request #669 ["Add passwords with user-specified special characters"] has been submitted to add this feature.

leoncho avatar Nov 07 '21 23:11 leoncho