feat: central function for random string
This commit is contained in:
parent
21f2a21609
commit
0023e52f79
3 changed files with 12 additions and 17 deletions
|
@ -7,9 +7,11 @@ use std::env;
|
|||
use std::str::FromStr;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
use chrono::{Datelike, SecondsFormat, Utc};
|
||||
use rand::distributions::Alphanumeric;
|
||||
use rand::{Rng, thread_rng};
|
||||
use tide::prelude::*;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, sqlx::FromRow)]
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, sqlx::FromRow)]
|
||||
pub struct AccountsNew {
|
||||
pub mail: String,
|
||||
pub auth_code: String,
|
||||
|
@ -295,3 +297,8 @@ pub fn read_csv(config: &Config) -> Result<Vec<Record>, Box<dyn std::error::Erro
|
|||
|
||||
Ok(records)
|
||||
}
|
||||
|
||||
// from https://rust-lang-nursery.github.io/rust-cookbook/algorithms/randomness.html#create-random-passwords-from-a-set-of-alphanumeric-characters
|
||||
pub fn random_string(len: usize) -> String {
|
||||
thread_rng().sample_iter(&Alphanumeric).take(len).map(char::from).collect()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue