Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SAMLAuthenticator.generatePassword(...) does not use same probability for all chars #7

Open
Marcono1234 opened this issue Dec 23, 2020 · 0 comments

Comments

@Marcono1234
Copy link

It appears SAMLAuthenticator.generatePassword(int) does not use the same probability for all chars:

char[] chars =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()".toCharArray();
byte[] bytes = new byte[len];
char[] pw = new char[len];
new SecureRandom().nextBytes(bytes);
for (i=0; i < bytes.length; i++) {
int randval = bytes[i] & 0xff;
pw[i] = chars[randval % chars.length];
}
return String.valueOf(pw);

There are 72 chars but a char is picked using effectively random(0, 255) % 72. Therefore the first 40 (= 256 % 72) chars are picked with a probability of 4/7, while the remaining 32 chars are picked with a probability of 3/7.

Though this is likely not that dramatic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant