From 9f6b00a62b6055cfa1288ae6bfe57db2dcbbfa2c Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Wed, 17 Feb 2021 16:32:49 +0100 Subject: [PATCH] Create password policy --- src/api_data/server_config.rs | 29 +++++++++++++++++++++++++++-- src/constants.rs | 19 +++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/api_data/server_config.rs b/src/api_data/server_config.rs index b9aced6..b66e8f6 100644 --- a/src/api_data/server_config.rs +++ b/src/api_data/server_config.rs @@ -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(), - } + }, } } } \ No newline at end of file diff --git a/src/constants.rs b/src/constants.rs index 616cf93..60d0dcb 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -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;