Skip to content

Commit e0395fd

Browse files
dhardyvks
authored andcommitted
Condense advice on password generation
1 parent 2da40a3 commit e0395fd

File tree

1 file changed

+10
-26
lines changed

1 file changed

+10
-26
lines changed

src/distributions/other.rs

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -39,34 +39,18 @@ use serde::{Serialize, Deserialize};
3939
///
4040
/// # Passwords
4141
///
42-
/// We caution that strings produced by sampling `Alphanumeric` tend not
43-
/// to be particularly memorable when used as passwords by humans.
44-
/// Instead, we suggest that human memorable passwords be created by
45-
/// drawing words independently and uniformly at random from a large wordlist.
42+
/// Users sometimes ask whether it is safe to use a string of random characters
43+
/// as a password. `Alphanumeric` generates from an alphabet of 62 symbols, thus
44+
/// each character can provide `log2(62) = 5.95...` bits of entropy. We suggest
45+
/// consulting external sources for more. One may start with the
46+
/// [Wikipedia article on Password Strength](https://en.wikipedia.org/wiki/Password_strength).
4647
///
48+
/// We caution that strings produced by sampling `Alphanumeric` tend not
49+
/// to be particularly memorable when used as passwords by humans.
50+
/// Drawing words from a specially-curated word-list such as
51+
/// [Diceware](https://en.wikipedia.org/wiki/Diceware) may be a better option
52+
/// for memorable passwords.
4753
/// Each random word contributes `log2(wordlist_length)` bits of entropy.
48-
///
49-
/// Among the widely reviewed wordlists, there are [Diceware](https://en.wikipedia.org/wiki/Diceware)
50-
/// wordlists for many major langauges, including some from security
51-
/// organizations like the E.F.F., and many of which further facilitate
52-
/// memorability by avoiding homophones and words with tricky spelling.
53-
///
54-
/// There exists [several crates](https://crates.io/search?q=diceware) for
55-
/// this but `rand::seq::SliceRandom::choose` works too:
56-
/// ```
57-
/// # use rand::Rng;
58-
/// #[allow(dead_code)]
59-
/// pub fn make_password<R: Rng>(wordlist: &[impl ::core::borrow::Borrow<str>], entropy: u32, rng: &mut R) -> String {
60-
/// use rand::seq::SliceRandom;
61-
/// use core::convert::TryInto;
62-
/// let entropy: f64 = entropy.into();
63-
/// let l: u32 = wordlist.len().try_into().unwrap();
64-
/// assert!( l > 0 );
65-
/// let l: f64 = l.into();
66-
/// let l = (entropy / l.log2()).ceil() as usize;
67-
/// (0..l).map(|_| wordlist.choose(rng).unwrap().borrow() ).collect::<String>()
68-
/// }
69-
/// ```
7054
#[derive(Debug)]
7155
#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
7256
pub struct Alphanumeric;

0 commit comments

Comments
 (0)