mirror of
https://github.com/kanidm/kanidm.git
synced 2025-02-23 12:37:00 +01:00
Clean up utils password rand generation. (#2727)
We previously used a "performance" optimisation in our password generation that was likely not needed. This optimisation did *not* impact password entropy or quality in the generation. To improve clarity, swap to the Uniform distribution instead.
This commit is contained in:
parent
2e206b2488
commit
5ff482542b
|
@ -1,6 +1,6 @@
|
|||
use crate::prelude::*;
|
||||
use hashbrown::HashSet;
|
||||
use rand::distributions::Distribution;
|
||||
use rand::distributions::{Distribution, Uniform};
|
||||
use rand::{thread_rng, Rng};
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -77,13 +77,11 @@ impl Distribution<char> for DistinctAlpha {
|
|||
const GEN_ASCII_STR_CHARSET: &[u8] = b"ABCDEFGHJKLMNPQRSTUVWXYZ\
|
||||
abcdefghjkpqrstuvwxyz\
|
||||
0123456789";
|
||||
// This probably needs to be checked for entropy/quality
|
||||
loop {
|
||||
let var = rng.next_u32() >> (32 - 6);
|
||||
if var < RANGE {
|
||||
return GEN_ASCII_STR_CHARSET[var as usize] as char;
|
||||
}
|
||||
}
|
||||
|
||||
let range = Uniform::new(0, RANGE);
|
||||
|
||||
let n = range.sample(rng);
|
||||
GEN_ASCII_STR_CHARSET[n as usize] as char
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue