mirror of
				https://gitlab.com/comunic/comunicapiv3
				synced 2025-10-31 07:34:45 +00:00 
			
		
		
		
	Create password policy
This commit is contained in:
		| @@ -2,7 +2,20 @@ | ||||
| //! | ||||
| //! @author Pierre Hubert | ||||
| use serde::Serialize; | ||||
| use crate::constants::conservation_policy; | ||||
|  | ||||
| use crate::constants::{conservation_policy, password_policy}; | ||||
|  | ||||
| #[derive(Serialize)] | ||||
| struct PasswordPolicy { | ||||
|     allow_email_in_password: bool, | ||||
|     allow_name_in_password: bool, | ||||
|     min_password_length: u64, | ||||
|     min_number_upper_case_letters: u64, | ||||
|     min_number_lower_case_letters: u64, | ||||
|     min_number_digits: u64, | ||||
|     min_number_special_characters: u64, | ||||
|     min_categories_presence: u64, | ||||
| } | ||||
|  | ||||
| #[derive(Serialize)] | ||||
| struct DataConservationPolicy { | ||||
| @@ -16,12 +29,24 @@ struct DataConservationPolicy { | ||||
|  | ||||
| #[derive(Serialize)] | ||||
| pub struct ServerConfig { | ||||
|     password_policy: PasswordPolicy, | ||||
|     data_conservation_policy: DataConservationPolicy, | ||||
| } | ||||
|  | ||||
| impl ServerConfig { | ||||
|     pub fn new() -> Self { | ||||
|         ServerConfig { | ||||
|             password_policy: PasswordPolicy { | ||||
|                 allow_email_in_password: password_policy::ALLOW_EMAIL_IN_PASSWORD, | ||||
|                 allow_name_in_password: password_policy::ALLOW_NAME_IN_PASSWORD, | ||||
|                 min_password_length: password_policy::MIN_PASSWORD_LENGTH, | ||||
|                 min_number_upper_case_letters: password_policy::MIN_NUMBER_UPPERCASE_LETTER, | ||||
|                 min_number_lower_case_letters: password_policy::MIN_NUMBER_LOWERCASE_LETTER, | ||||
|                 min_number_digits: password_policy::MIN_NUMBER_DIGITS, | ||||
|                 min_number_special_characters: password_policy::MIN_NUMBER_SPECIAL_CHARACTERS, | ||||
|                 min_categories_presence: password_policy::MIN_CATEGORIES_PRESENCE, | ||||
|             }, | ||||
|  | ||||
|             data_conservation_policy: DataConservationPolicy { | ||||
|                 min_inactive_account_lifetime: conservation_policy::MIN_INACTIVE_ACCOUNT_LIFETIME.as_secs(), | ||||
|                 min_notification_lifetime: conservation_policy::MIN_NOTIFICATIONS_LIFETIME.as_secs(), | ||||
| @@ -29,7 +54,7 @@ impl ServerConfig { | ||||
|                 min_posts_lifetime: conservation_policy::MIN_POSTS_LIFETIME.as_secs(), | ||||
|                 min_conversation_messages_lifetime: conservation_policy::MIN_CONVERSATION_MESSAGES_LIFETIME.as_secs(), | ||||
|                 min_likes_lifetime: conservation_policy::MIN_LIKES_LIFETIME.as_secs(), | ||||
|             } | ||||
|             }, | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -59,6 +59,25 @@ pub mod database_tables_names { | ||||
|     pub const NOTIFICATIONS_TABLE: &str = "comunic_notifications"; | ||||
| } | ||||
|  | ||||
| /// Password policy | ||||
| pub mod password_policy { | ||||
|     /// Allow email in password ? | ||||
|     pub const ALLOW_EMAIL_IN_PASSWORD: bool = false; | ||||
|  | ||||
|     /// Allow user name in password ? | ||||
|     pub const ALLOW_NAME_IN_PASSWORD: bool = false; | ||||
|  | ||||
|     /// Minimal length of password | ||||
|     pub const MIN_PASSWORD_LENGTH: u64 = 8; | ||||
|  | ||||
|     /// Password composition policy | ||||
|     pub const MIN_NUMBER_LOWERCASE_LETTER: u64 = 1; | ||||
|     pub const MIN_NUMBER_UPPERCASE_LETTER: u64 = 1; | ||||
|     pub const MIN_NUMBER_DIGITS: u64 = 1; | ||||
|     pub const MIN_NUMBER_SPECIAL_CHARACTERS: u64 = 1; | ||||
|     pub const MIN_CATEGORIES_PRESENCE: u64 = 2; | ||||
| } | ||||
|  | ||||
| /// Minimal conversation policy | ||||
| pub mod conservation_policy { | ||||
|     use std::time::Duration; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user