[gen] Real words: memorable passwords from EFF words a US English dictionary knows; strict-site symbols ASCII only (v0.2.1)
This commit is contained in:
@@ -48,23 +48,16 @@ const DIGITS: [char; 10] = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
|
||||
|
||||
// ---------- word lists ----------
|
||||
|
||||
/// The EFF large wordlist (7,776 words), with its four hyphenated words made plain: the hyphen is
|
||||
/// removed, and `yo-yo` (the list also has `yoyo`) becomes `yoyos`, so all 7,776 stay distinct.
|
||||
pub static EFF_WORDS: LazyLock<Vec<String>> = LazyLock::new(|| {
|
||||
include_str!("../wordlists/eff_large_wordlist.txt")
|
||||
.lines()
|
||||
.filter_map(|l| l.split('\t').nth(1))
|
||||
.map(|w| match w.trim() {
|
||||
"yo-yo" => "yoyos".to_owned(),
|
||||
w => w.replace('-', ""),
|
||||
})
|
||||
.collect()
|
||||
});
|
||||
|
||||
fn plain_list(text: &'static str) -> Vec<&'static str> {
|
||||
text.lines().filter(|l| !l.starts_with('#')).flat_map(str::split_whitespace).collect()
|
||||
}
|
||||
|
||||
/// The words of memorable passwords (7,322): the EFF large wordlist without the words a standard US
|
||||
/// English spellchecker dictionary does not know (brand names, names, coinages, hyphenated words).
|
||||
/// See `wordlists/SOURCES.md`.
|
||||
pub static MEMORABLE_WORDS: LazyLock<Vec<&str>> =
|
||||
LazyLock::new(|| plain_list(include_str!("../wordlists/memorable.txt")));
|
||||
|
||||
static NOUNS: LazyLock<Vec<&str>> = LazyLock::new(|| plain_list(include_str!("../wordlists/nouns.txt")));
|
||||
static ADJECTIVES: LazyLock<Vec<&str>> = LazyLock::new(|| plain_list(include_str!("../wordlists/adjectives.txt")));
|
||||
static VERBS: LazyLock<Vec<&str>> = LazyLock::new(|| plain_list(include_str!("../wordlists/verbs.txt")));
|
||||
@@ -144,7 +137,7 @@ pub const MAX_WORDS: u8 = 10;
|
||||
/// Bits of entropy of a memorable password with these options.
|
||||
pub fn memorable_entropy(o: &MemorableOptions) -> f64 {
|
||||
let n = o.words.clamp(MIN_WORDS, MAX_WORDS) as f64;
|
||||
let per_word = (EFF_WORDS.len() as f64).log2() + if o.digit_after_word { 10f64.log2() } else { 0.0 };
|
||||
let per_word = (MEMORABLE_WORDS.len() as f64).log2() + if o.digit_after_word { 10f64.log2() } else { 0.0 };
|
||||
n * per_word + (n - 1.0) * (o.separator.choices().len() as f64).log2()
|
||||
}
|
||||
|
||||
@@ -157,7 +150,7 @@ pub fn memorable(o: &MemorableOptions) -> Generated {
|
||||
if i > 0 {
|
||||
out.push(pick(&seps));
|
||||
}
|
||||
let w = &EFF_WORDS[rng().random_range(0..EFF_WORDS.len())];
|
||||
let w = pick(&MEMORABLE_WORDS);
|
||||
if o.capitalize {
|
||||
out.push_str(&capitalize(w));
|
||||
} else {
|
||||
@@ -376,6 +369,7 @@ pub fn nickname(title: &str, o: &NicknameOptions) -> Result<Generated, GenError>
|
||||
}
|
||||
|
||||
// ---------- random, strict site, PIN ----------
|
||||
// Only English letters A–Z/a–z, digits 0–9 and ASCII symbols: every keyboard layout can type them.
|
||||
|
||||
pub const RANDOM_SYMBOLS: &str = "!@#$%^&*()-_=+[]{};:,.?/~";
|
||||
pub const LOOKALIKES: &str = "Il1O0o|";
|
||||
@@ -452,7 +446,8 @@ pub struct StrictOptions {
|
||||
pub upper: ClassRule,
|
||||
pub digits: ClassRule,
|
||||
pub symbols: ClassRule,
|
||||
/// The symbols the site accepts.
|
||||
/// The symbols the site accepts. Only ASCII symbols count: letters, digits, spaces and anything
|
||||
/// outside ASCII (`€`, `§`, `ž`) are ignored.
|
||||
pub allowed_symbols: String,
|
||||
}
|
||||
|
||||
@@ -471,8 +466,7 @@ impl Default for StrictOptions {
|
||||
|
||||
pub fn strict(o: &StrictOptions) -> Result<Generated, GenError> {
|
||||
let len = check_length(o.length)?;
|
||||
let mut symbols: Vec<char> =
|
||||
o.allowed_symbols.chars().filter(|c| !c.is_alphanumeric() && !c.is_whitespace()).collect();
|
||||
let mut symbols: Vec<char> = o.allowed_symbols.chars().filter(char::is_ascii_punctuation).collect();
|
||||
symbols.sort_unstable();
|
||||
symbols.dedup();
|
||||
let rules = [
|
||||
|
||||
Reference in New Issue
Block a user