@@ -7,25 +7,21 @@ use serde::{Deserialize, Serialize};
77#[ derive( Debug , Clone , Serialize , Deserialize , PartialEq ) ]
88pub struct Auth {
99 /// Whether or not to require an email on signup.
10- #[ serde( default = "EmailOnSignup::default " ) ]
10+ #[ serde( default = "Auth::default_email_on_signup " ) ]
1111 pub email_on_signup : EmailOnSignup ,
12- /// The minimum password length.
13- #[ serde( default = "Auth::default_min_password_length" ) ]
14- pub min_password_length : usize ,
15- /// The maximum password length.
16- #[ serde( default = "Auth::default_max_password_length" ) ]
17- pub max_password_length : usize ,
1812 /// The secret key used to sign JWT tokens.
1913 #[ serde( default = "Auth::default_secret_key" ) ]
2014 pub secret_key : SecretKey ,
15+ /// The password constraints
16+ #[ serde( default = "Auth::default_password_constraints" ) ]
17+ pub password_constraints : PasswordConstraints ,
2118}
2219
2320impl Default for Auth {
2421 fn default ( ) -> Self {
2522 Self {
2623 email_on_signup : EmailOnSignup :: default ( ) ,
27- min_password_length : Self :: default_min_password_length ( ) ,
28- max_password_length : Self :: default_max_password_length ( ) ,
24+ password_constraints : Self :: default_password_constraints ( ) ,
2925 secret_key : Self :: default_secret_key ( ) ,
3026 }
3127 }
@@ -36,17 +32,17 @@ impl Auth {
3632 self . secret_key = SecretKey :: new ( secret_key) ;
3733 }
3834
39- fn default_min_password_length ( ) -> usize {
40- 6
41- }
42-
43- fn default_max_password_length ( ) -> usize {
44- 64
35+ fn default_email_on_signup ( ) -> EmailOnSignup {
36+ EmailOnSignup :: default ( )
4537 }
4638
4739 fn default_secret_key ( ) -> SecretKey {
4840 SecretKey :: new ( "MaxVerstappenWC2021" )
4941 }
42+
43+ fn default_password_constraints ( ) -> PasswordConstraints {
44+ PasswordConstraints :: default ( )
45+ }
5046}
5147
5248/// Whether the email is required on signup or not.
@@ -119,6 +115,35 @@ impl fmt::Display for SecretKey {
119115 }
120116}
121117
118+ #[ derive( Debug , Clone , Serialize , Deserialize , PartialEq ) ]
119+ pub struct PasswordConstraints {
120+ /// The minimum password length.
121+ #[ serde( default = "PasswordConstraints::default_min_password_length" ) ]
122+ pub min_password_length : usize ,
123+ /// The maximum password length.
124+ #[ serde( default = "PasswordConstraints::default_max_password_length" ) ]
125+ pub max_password_length : usize ,
126+ }
127+
128+ impl Default for PasswordConstraints {
129+ fn default ( ) -> Self {
130+ Self {
131+ min_password_length : Self :: default_min_password_length ( ) ,
132+ max_password_length : Self :: default_max_password_length ( ) ,
133+ }
134+ }
135+ }
136+
137+ impl PasswordConstraints {
138+ fn default_min_password_length ( ) -> usize {
139+ 6
140+ }
141+
142+ fn default_max_password_length ( ) -> usize {
143+ 64
144+ }
145+ }
146+
122147#[ cfg( test) ]
123148mod tests {
124149 use super :: SecretKey ;
0 commit comments