@@ -39,34 +39,18 @@ use serde::{Serialize, Deserialize};
39
39
///
40
40
/// # Passwords
41
41
///
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).
46
47
///
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.
47
53
/// 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
- /// ```
70
54
#[ derive( Debug ) ]
71
55
#[ cfg_attr( feature = "serde1" , derive( Serialize , Deserialize ) ) ]
72
56
pub struct Alphanumeric ;
0 commit comments