fix(users): add password validations (#4555)

Co-authored-by: Rachit Naithani <rachit.naithani@juspay.in>
This commit is contained in:
Riddhiagrawal001
2024-05-07 18:38:46 +05:30
committed by GitHub
parent 1b5b566387
commit 25fe4deb8e
3 changed files with 59 additions and 7 deletions

View File

@ -8,6 +8,7 @@ use argon2::{
use common_utils::errors::CustomResult;
use error_stack::ResultExt;
use masking::{ExposeInterface, Secret};
use rand::{seq::SliceRandom, Rng};
use crate::core::errors::UserErrors;
@ -38,3 +39,20 @@ pub fn is_correct_password(
}
.change_context(UserErrors::InternalServerError)
}
pub fn get_temp_password() -> Secret<String> {
let uuid_pass = uuid::Uuid::new_v4().to_string();
let mut rng = rand::thread_rng();
let special_chars: Vec<char> = "!@#$%^&*()-_=+[]{}|;:,.<>?".chars().collect();
let special_char = special_chars.choose(&mut rng).unwrap_or(&'@');
Secret::new(format!(
"{}{}{}{}{}",
uuid_pass,
rng.gen_range('A'..='Z'),
special_char,
rng.gen_range('a'..='z'),
rng.gen_range('0'..='9'),
))
}