scouter_auth/
util.rs

1use password_auth::generate_hash;
2use rand::distr::Alphanumeric;
3use rand::Rng;
4use rayon::prelude::*;
5
6pub fn generate_recovery_codes_with_hashes(count: usize) -> (Vec<String>, Vec<String>) {
7    // Generate codes in parallel
8    let results: Vec<(String, String)> = (0..count)
9        .into_par_iter()
10        .map(|_| {
11            // Generate random code
12            let code: String = rand::rng()
13                .sample_iter(&Alphanumeric)
14                .take(16)
15                .map(char::from)
16                .collect();
17
18            // Hash the code
19            let hashed = generate_hash(&code);
20
21            (code, hashed)
22        })
23        .collect();
24
25    // Unzip results into separate vectors
26    results.into_iter().unzip()
27}