feat: central function for random string

This commit is contained in:
silver 2023-07-30 02:02:56 +01:00
parent 21f2a21609
commit 0023e52f79
3 changed files with 12 additions and 17 deletions

View file

@ -1,4 +1,4 @@
use crate::{get_now, Accounts, AccountsPending, State};
use crate::{Accounts, AccountsPending, State, get_now_iso, AccountsNew, random_string};
use ldap3::exop::PasswordModify;
use ldap3::result::ExopResult;
use ldap3::{LdapConn, Scope};
@ -155,12 +155,6 @@ async fn db_pending_clear_expired(pool: &Pool<Sqlite>) -> Result<Vec<AccountsPen
.await
}
fn create_random_string(length: usize) -> String {
use rand::distributions::Alphanumeric;
use rand::{thread_rng, Rng};
thread_rng().sample_iter(&Alphanumeric).take(length).map(char::from).collect()
}
#[derive(Debug, Deserialize)]
pub struct LdapUserVerify {
@ -267,7 +261,7 @@ async fn account_verification_new_account(ldap: &mut LdapConn, user_details: &Ac
let dn = format!("uid={},ou=users,dc=skynet,dc=ie", user);
let home_directory = format!("/home/{}", user);
let password_tmp = create_random_string(50);
let password_tmp = random_string(50);
let labeled_uri = format!("ldap:///ou=groups,dc=skynet,dc=ie??sub?(&(objectclass=posixgroup)(memberuid={}))", user);
let sk_mail = format!("{}@skynet.ie", user);
let sk_created = get_sk_created();