mirror of
https://github.com/kanidm/kanidm.git
synced 2025-02-23 20:47:01 +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 crate::prelude::*;
|
||||||
use hashbrown::HashSet;
|
use hashbrown::HashSet;
|
||||||
use rand::distributions::Distribution;
|
use rand::distributions::{Distribution, Uniform};
|
||||||
use rand::{thread_rng, Rng};
|
use rand::{thread_rng, Rng};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -77,13 +77,11 @@ impl Distribution<char> for DistinctAlpha {
|
||||||
const GEN_ASCII_STR_CHARSET: &[u8] = b"ABCDEFGHJKLMNPQRSTUVWXYZ\
|
const GEN_ASCII_STR_CHARSET: &[u8] = b"ABCDEFGHJKLMNPQRSTUVWXYZ\
|
||||||
abcdefghjkpqrstuvwxyz\
|
abcdefghjkpqrstuvwxyz\
|
||||||
0123456789";
|
0123456789";
|
||||||
// This probably needs to be checked for entropy/quality
|
|
||||||
loop {
|
let range = Uniform::new(0, RANGE);
|
||||||
let var = rng.next_u32() >> (32 - 6);
|
|
||||||
if var < RANGE {
|
let n = range.sample(rng);
|
||||||
return GEN_ASCII_STR_CHARSET[var as usize] as char;
|
GEN_ASCII_STR_CHARSET[n as usize] as char
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue