Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
fix(users): add password validations (#4489)
Riddhiagrawal00167794da36ec2
diff --git a/crates/router/src/consts/user.rs b/crates/router/src/consts/user.rsindex 1cda969f78..f14610649f 100644--- a/crates/router/src/consts/user.rs+++ b/crates/router/src/consts/user.rs@@ -1,3 +1,5 @@pub const MAX_NAME_LENGTH: usize = 70;pub const MAX_COMPANY_NAME_LENGTH: usize = 70;pub const BUSINESS_EMAIL: &str = "[email protected]";+pub const MAX_PASSWORD_LENGTH: usize = 70;+pub const MIN_PASSWORD_LENGTH: usize = 8;diff --git a/crates/router/src/types/domain/user.rs b/crates/router/src/types/domain/user.rsindex fab02df88b..0b971d8203 100644--- a/crates/router/src/types/domain/user.rs+++ b/crates/router/src/types/domain/user.rs@@ -155,7 +155,32 @@ pub struct UserPassword(Secret<String>);impl UserPassword {pub fn new(password: Secret<String>) -> UserResult<Self> {let password = password.expose();- if password.is_empty() {++ let mut has_upper_case = false;+ let mut has_lower_case = false;+ let mut has_numeric_value = false;+ let mut has_special_character = false;+ let mut has_whitespace = false;++ for c in password.chars() {+ has_upper_case = has_upper_case || c.is_uppercase();+ has_lower_case = has_lower_case || c.is_lowercase();+ has_numeric_value = has_numeric_value || c.is_numeric();+ has_special_character =+ has_special_character || !(c.is_alphanumeric() && c.is_whitespace());+ has_whitespace = has_whitespace || c.is_whitespace();+ }++ let is_password_format_valid = has_upper_case+ && has_lower_case+ && has_numeric_value+ && has_special_character+ && !has_whitespace;++ let is_too_long = password.graphemes(true).count() > consts::user::MAX_PASSWORD_LENGTH;+ let is_too_short = password.graphemes(true).count() < consts::user::MIN_PASSWORD_LENGTH;++ if is_too_short || is_too_long || !is_password_format_valid {Err(UserErrors::PasswordParsingError.into())} else {Ok(Self(password.into()))