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?
Here is how you can make sure your generated password meets your password criteria, e.g: in your case, i would use this regex:
This regex meets the following criteria:
1.- at least 1 lowerCase letter
2.- at least 1 upperCase letter
3.- at least 1 digit(number)
4.- at least 6 characters (note that adding a number greater than 6 after the comma at the end of the regex, will now meet a criteria that at least 6 characters and a max of whatever you put in there)
What this code does is that
while
your generated password doesn't meet your criteria, it will loop thefor
loop over and over.Here's one that I wrote a while back:
This will be the easiest one :)
Implemented a PasswordBuilder. Supports passwrod limit, must have characters and how much of them, char ranges and a list of them.
Usage Example:
Example result:
QU1GY7p+j+-PUW+_
Example result:
%,4NX
Implementation:
This is also a nice one:
It however does not guarantee that the password always contains both digits and letters, but most of the aforementioned suggestions also doesn't do that.
A bit late, but I usually use the following code:
There is no guarantee that there will always be a number, special character, lower-case and upper-case character in the password. This could be enforced by first adding a character and a digit, however this would create passwords that are a bit more predictable.