@@ -7,25 +7,21 @@ use serde::{Deserialize, Serialize};
7
7
#[ derive( Debug , Clone , Serialize , Deserialize , PartialEq ) ]
8
8
pub struct Auth {
9
9
/// Whether or not to require an email on signup.
10
- #[ serde( default = "EmailOnSignup::default " ) ]
10
+ #[ serde( default = "Auth::default_email_on_signup " ) ]
11
11
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 ,
18
12
/// The secret key used to sign JWT tokens.
19
13
#[ serde( default = "Auth::default_secret_key" ) ]
20
14
pub secret_key : SecretKey ,
15
+ /// The password constraints
16
+ #[ serde( default = "Auth::default_password_constraints" ) ]
17
+ pub password_constraints : PasswordConstraints ,
21
18
}
22
19
23
20
impl Default for Auth {
24
21
fn default ( ) -> Self {
25
22
Self {
26
23
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 ( ) ,
29
25
secret_key : Self :: default_secret_key ( ) ,
30
26
}
31
27
}
@@ -36,17 +32,17 @@ impl Auth {
36
32
self . secret_key = SecretKey :: new ( secret_key) ;
37
33
}
38
34
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 ( )
45
37
}
46
38
47
39
fn default_secret_key ( ) -> SecretKey {
48
40
SecretKey :: new ( "MaxVerstappenWC2021" )
49
41
}
42
+
43
+ fn default_password_constraints ( ) -> PasswordConstraints {
44
+ PasswordConstraints :: default ( )
45
+ }
50
46
}
51
47
52
48
/// Whether the email is required on signup or not.
@@ -119,6 +115,35 @@ impl fmt::Display for SecretKey {
119
115
}
120
116
}
121
117
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
+
122
147
#[ cfg( test) ]
123
148
mod tests {
124
149
use super :: SecretKey ;
0 commit comments