From 5b3e56954e9eaa4eb873d8e9b955f28e0af8887f Mon Sep 17 00:00:00 2001 From: finga Date: Fri, 28 Aug 2020 22:03:42 +0200 Subject: [PATCH] Improve random key generation --- src/main.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5f5fd23..ab195e9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -60,11 +60,10 @@ fn reset_prepare(config: &Ldap0rConfig, keys: &Keys, email_address: &str) -> Res if rs.len() == 1 { // generate key - let mut key = String::with_capacity(64); let mut rng = rand::thread_rng(); - for _ in 0..64 { - key.push(BASE62[rng.gen::() % 62] as char); - } + let key: String = (0..64) + .map(|_| BASE62[rng.gen::() % 62] as char) + .collect(); // store key with id let keys = Arc::clone(&keys.keys);