I want to give maybe a million password to some users that should be like:
- It must have at least 6 characters
- It must have digits and also letters
Should I use Random
here? How?
I want to give maybe a million password to some users that should be like:
Should I use Random
here? How?
When using Apache's
RandomStringUtils
for security reasons (i.e. passwords), it's very important to combine the use of aSecureRandom
source:Use SecureRandom, it provides a more random passwords.
You can create a single password using something like this (note: untested code).
Note that this does not guarantee that the every password will have both digits and characters.
RandomStringUtils from Apache Commons Lang provide some methods to generate a randomized String, that can be used as password.
Here are some examples of 8-characters passwords creation:
which creates the following result:
Of course, you have also methods that may restrict the set of characters allowed for the password generation:
will create only passwords with the characters a, b, c, D, E, F, 1, 2 or 3:
What I would do is something like this: