1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-22 21:39:21 +00:00

Create password policy

This commit is contained in:
Pierre HUBERT 2021-02-17 16:32:49 +01:00
parent 2edffa36d8
commit 9f6b00a62b
2 changed files with 46 additions and 2 deletions

View File

@ -2,7 +2,20 @@
//! //!
//! @author Pierre Hubert //! @author Pierre Hubert
use serde::Serialize; 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)] #[derive(Serialize)]
struct DataConservationPolicy { struct DataConservationPolicy {
@ -16,12 +29,24 @@ struct DataConservationPolicy {
#[derive(Serialize)] #[derive(Serialize)]
pub struct ServerConfig { pub struct ServerConfig {
password_policy: PasswordPolicy,
data_conservation_policy: DataConservationPolicy, data_conservation_policy: DataConservationPolicy,
} }
impl ServerConfig { impl ServerConfig {
pub fn new() -> Self { pub fn new() -> Self {
ServerConfig { 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 { data_conservation_policy: DataConservationPolicy {
min_inactive_account_lifetime: conservation_policy::MIN_INACTIVE_ACCOUNT_LIFETIME.as_secs(), min_inactive_account_lifetime: conservation_policy::MIN_INACTIVE_ACCOUNT_LIFETIME.as_secs(),
min_notification_lifetime: conservation_policy::MIN_NOTIFICATIONS_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_posts_lifetime: conservation_policy::MIN_POSTS_LIFETIME.as_secs(),
min_conversation_messages_lifetime: conservation_policy::MIN_CONVERSATION_MESSAGES_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(), min_likes_lifetime: conservation_policy::MIN_LIKES_LIFETIME.as_secs(),
} },
} }
} }
} }

View File

@ -59,6 +59,25 @@ pub mod database_tables_names {
pub const NOTIFICATIONS_TABLE: &str = "comunic_notifications"; 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 /// Minimal conversation policy
pub mod conservation_policy { pub mod conservation_policy {
use std::time::Duration; use std::time::Duration;