Skip to content

Commit

Permalink
Add password strength and safe characters rules (#147)
Browse files Browse the repository at this point in the history
The schema validation now includes rules to check password strength and
safe characters. Password strength calculates using length, presence of
uppercase and lowercase letters, numbers, special characters, and checks
for common weak passwords. It is adjustable to fit a 0 to 10 scale. The
safe characters rule checks if a password only contains safe characters.
The update ensures better password validation and security.
  • Loading branch information
SmetDenis committed Apr 6, 2024
1 parent 7a40ce8 commit 80191ad
Show file tree
Hide file tree
Showing 11 changed files with 489 additions and 147 deletions.
26 changes: 21 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
<!-- auto-update:/top-badges -->

<!-- auto-update:rules-counter -->
[![Static Badge](https://img.shields.io/badge/Rules-332-green?label=Total%20number%20of%20rules&labelColor=darkgreen&color=gray)](schema-examples/full.yml)
[![Static Badge](https://img.shields.io/badge/Rules-118-green?label=Cell%20rules&labelColor=blue&color=gray)](src/Rules/Cell)
[![Static Badge](https://img.shields.io/badge/Rules-339-green?label=Total%20number%20of%20rules&labelColor=darkgreen&color=gray)](schema-examples/full.yml)
[![Static Badge](https://img.shields.io/badge/Rules-125-green?label=Cell%20rules&labelColor=blue&color=gray)](src/Rules/Cell)
[![Static Badge](https://img.shields.io/badge/Rules-206-green?label=Aggregate%20rules&labelColor=blue&color=gray)](src/Rules/Aggregate)
[![Static Badge](https://img.shields.io/badge/Rules-8-green?label=Extra%20checks&labelColor=blue&color=gray)](#extra-checks)
[![Static Badge](https://img.shields.io/badge/Rules-20/11/20-green?label=Plan%20to%20add&labelColor=gray&color=gray)](tests/schemas/todo.yml)
[![Static Badge](https://img.shields.io/badge/Rules-18/11/20-green?label=Plan%20to%20add&labelColor=gray&color=gray)](tests/schemas/todo.yml)
<!-- auto-update:/rules-counter -->

A console utility designed for validating CSV files against a strictly defined schema and validation rules outlined
Expand Down Expand Up @@ -475,6 +475,20 @@ columns:
is_base64: true # Validate if a string is Base64-encoded. Example: "cmVzcGVjdCE=".
is_angle: true # Check if the cell value is a valid angle (0.0 to 360.0).

# Safity checks
# Password strength calculation criteria include: Length (max 5 points, +1 every 2 characters),
# presence of uppercase letters (+1), lowercase letters (+1), numbers (+1), special characters (+1),
# spaces (+1), and penalties for consecutive sequences of uppercase, lowercase, or
# numbers (-0.5 each), repetitive sequences (-0.75 each), common weak passwords like "qwerty",
# and passwords under 6 characters (-2). Adjust scores to a 0 to 10 scale, with a minimum score of 0.
password_strength_min: 1 # x >= 1
password_strength_greater: 2 # x > 2
password_strength_not: 0 # x != 0
password_strength: 7 # x == 7
password_strength_less: 8 # x < 8
password_strength_max: 9 # x <= 9
is_password_safe_chars: true # Check that the cell value contains only safe characters for regular passwords. Allowed characters: a-z, A-Z, 0-9, !@#$%^&*()_+-=[]{};:'"|,.<>/?~.

# Internet
is_ip: true # Both: IPv4 or IPv6.
is_ip_v4: true # Only IPv4. Example: "127.0.0.1".
Expand Down Expand Up @@ -1050,7 +1064,8 @@ columns:
rules:
not_empty: true
is_trimmed: true
regex: /^[a-zA-Z\d!@#$%^&*()_+\-=\[\]{};':"\|,.<>\/?~]{6,}$/ # Safe list of special characters for passwords.
is_password_safe_chars: true
password_strength_min: 7
contains_none: [ "password", "123456", "qwerty", " " ]
charset: UTF-8
length_min: 6
Expand Down Expand Up @@ -1291,7 +1306,8 @@ columns:
rules:
not_empty: true
is_trimmed: true
regex: '/^[a-zA-Z\d!@#$%^&*()_+\-=\[\]{};'':"\|,.<>\/?~]{6,}$/'
is_password_safe_chars: true
password_strength_min: 7
contains_none:
- password
- '123456'
Expand Down
286 changes: 147 additions & 139 deletions schema-examples/full.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,145 +33,153 @@
"required" : true,

"rules" : {
"preset" : "my-preset/login",
"not_empty" : true,
"exact_value" : "Some string",
"allow_values" : ["y", "n", ""],
"not_allow_values" : ["invalid"],

"regex" : "\/^[\\d]{2}$\/",

"length_min" : 1,
"length_greater" : 2,
"length_not" : 0,
"length" : 7,
"length_less" : 8,
"length_max" : 9,

"is_trimmed" : true,
"is_lowercase" : true,
"is_uppercase" : true,
"is_capitalize" : true,

"word_count_min" : 1,
"word_count_greater" : 2,
"word_count_not" : 0,
"word_count" : 7,
"word_count_less" : 8,
"word_count_max" : 9,

"contains" : "World",
"contains_none" : ["a", "b"],
"contains_one" : ["a", "b"],
"contains_any" : ["a", "b"],
"contains_all" : ["a", "b"],
"starts_with" : "prefix ",
"ends_with" : " suffix",

"num_min" : 1,
"num_greater" : 2,
"num_not" : 5,
"num" : 7,
"num_less" : 8,
"num_max" : 9,
"is_int" : true,
"is_float" : true,

"precision_min" : 1,
"precision_greater" : 2,
"precision_not" : 0,
"precision" : 7,
"precision_less" : 8,
"precision_max" : 9,

"date_min" : "-100 years",
"date_greater" : "-99 days",
"date_not" : "2006-01-02 15:04:05 -0700 Europe\/Rome",
"date" : "01 Jan 2000",
"date_less" : "now",
"date_max" : "+1 day",
"date_format" : "Y-m-d",
"is_date" : true,
"is_timezone" : true,
"is_timezone_offset" : true,
"is_time" : true,
"is_leap_year" : true,

"date_interval_min" : "PT0S",
"date_interval_greater" : "1day 1sec",
"date_interval_not" : "100 days",
"date_interval" : "P2W",
"date_interval_less" : "PT23H59M59S",
"date_interval_max" : "P1Y",

"date_age_min" : 1,
"date_age_greater" : 14,
"date_age_not" : 18,
"date_age" : 21,
"date_age_less" : 99,
"date_age_max" : 100,

"is_bool" : true,
"is_binary" : true,
"is_octal" : true,
"is_hex" : true,
"is_uuid" : true,
"is_slug" : true,
"is_currency_code" : true,
"is_base64" : true,
"is_angle" : true,

"is_ip" : true,
"is_ip_v4" : true,
"is_ip_v6" : true,
"is_ip_private" : true,
"is_ip_reserved" : true,
"ip_v4_range" : ["127.0.0.1-127.0.0.5", "127.0.0.0\/21"],
"is_mac_address" : true,
"is_domain" : true,
"is_public_domain_suffix" : true,
"is_url" : true,
"is_email" : true,

"is_json" : true,
"is_latitude" : true,
"is_longitude" : true,
"is_geohash" : true,
"is_cardinal_direction" : true,
"is_usa_market_name" : true,

"is_country_code" : "alpha-2",
"is_language_code" : "alpha-2",

"is_file_exists" : true,
"is_dir_exists" : true,

"is_dir_exists" : true,
"is_fibonacci" : true,
"is_prime_number" : true,
"is_even" : true,
"is_odd" : true,
"is_roman" : true,
"is_luhn" : true,

"phone" : "ALL",
"postal_code" : "US",
"is_iban" : true,
"is_bic" : true,
"is_imei" : true,
"is_isbn" : true,

"is_version" : true,
"is_punct" : true,
"is_vowel" : true,
"is_consonant" : true,
"is_alnum" : true,
"is_alpha" : true,
"is_hex_rgb_color" : true,

"hash" : "set_algo",
"charset" : "charset_code",
"credit_card" : "Any"
"preset" : "my-preset/login",
"not_empty" : true,
"exact_value" : "Some string",
"allow_values" : ["y", "n", ""],
"not_allow_values" : ["invalid"],

"regex" : "\/^[\\d]{2}$\/",

"length_min" : 1,
"length_greater" : 2,
"length_not" : 0,
"length" : 7,
"length_less" : 8,
"length_max" : 9,

"is_trimmed" : true,
"is_lowercase" : true,
"is_uppercase" : true,
"is_capitalize" : true,

"word_count_min" : 1,
"word_count_greater" : 2,
"word_count_not" : 0,
"word_count" : 7,
"word_count_less" : 8,
"word_count_max" : 9,

"contains" : "World",
"contains_none" : ["a", "b"],
"contains_one" : ["a", "b"],
"contains_any" : ["a", "b"],
"contains_all" : ["a", "b"],
"starts_with" : "prefix ",
"ends_with" : " suffix",

"num_min" : 1,
"num_greater" : 2,
"num_not" : 5,
"num" : 7,
"num_less" : 8,
"num_max" : 9,
"is_int" : true,
"is_float" : true,

"precision_min" : 1,
"precision_greater" : 2,
"precision_not" : 0,
"precision" : 7,
"precision_less" : 8,
"precision_max" : 9,

"date_min" : "-100 years",
"date_greater" : "-99 days",
"date_not" : "2006-01-02 15:04:05 -0700 Europe\/Rome",
"date" : "01 Jan 2000",
"date_less" : "now",
"date_max" : "+1 day",
"date_format" : "Y-m-d",
"is_date" : true,
"is_timezone" : true,
"is_timezone_offset" : true,
"is_time" : true,
"is_leap_year" : true,

"date_interval_min" : "PT0S",
"date_interval_greater" : "1day 1sec",
"date_interval_not" : "100 days",
"date_interval" : "P2W",
"date_interval_less" : "PT23H59M59S",
"date_interval_max" : "P1Y",

"date_age_min" : 1,
"date_age_greater" : 14,
"date_age_not" : 18,
"date_age" : 21,
"date_age_less" : 99,
"date_age_max" : 100,

"is_bool" : true,
"is_binary" : true,
"is_octal" : true,
"is_hex" : true,
"is_uuid" : true,
"is_slug" : true,
"is_currency_code" : true,
"is_base64" : true,
"is_angle" : true,

"password_strength_min" : 1,
"password_strength_greater" : 2,
"password_strength_not" : 0,
"password_strength" : 7,
"password_strength_less" : 8,
"password_strength_max" : 9,
"is_password_safe_chars" : true,

"is_ip" : true,
"is_ip_v4" : true,
"is_ip_v6" : true,
"is_ip_private" : true,
"is_ip_reserved" : true,
"ip_v4_range" : ["127.0.0.1-127.0.0.5", "127.0.0.0\/21"],
"is_mac_address" : true,
"is_domain" : true,
"is_public_domain_suffix" : true,
"is_url" : true,
"is_email" : true,

"is_json" : true,
"is_latitude" : true,
"is_longitude" : true,
"is_geohash" : true,
"is_cardinal_direction" : true,
"is_usa_market_name" : true,

"is_country_code" : "alpha-2",
"is_language_code" : "alpha-2",

"is_file_exists" : true,
"is_dir_exists" : true,

"is_dir_exists" : true,
"is_fibonacci" : true,
"is_prime_number" : true,
"is_even" : true,
"is_odd" : true,
"is_roman" : true,
"is_luhn" : true,

"phone" : "ALL",
"postal_code" : "US",
"is_iban" : true,
"is_bic" : true,
"is_imei" : true,
"is_isbn" : true,

"is_version" : true,
"is_punct" : true,
"is_vowel" : true,
"is_consonant" : true,
"is_alnum" : true,
"is_alpha" : true,
"is_hex_rgb_color" : true,

"hash" : "set_algo",
"charset" : "charset_code",
"credit_card" : "Any"
},
"aggregate_rules" : {
"preset" : "my-preset/login",
Expand Down
8 changes: 8 additions & 0 deletions schema-examples/full.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@
'is_base64' => true,
'is_angle' => true,

'password_strength_min' => 1,
'password_strength_greater' => 2,
'password_strength_not' => 0,
'password_strength' => 7,
'password_strength_less' => 8,
'password_strength_max' => 9,
'is_password_safe_chars' => true,

'is_ip' => true,
'is_ip_v4' => true,
'is_ip_v6' => true,
Expand Down
14 changes: 14 additions & 0 deletions schema-examples/full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,20 @@ columns:
is_base64: true # Validate if a string is Base64-encoded. Example: "cmVzcGVjdCE=".
is_angle: true # Check if the cell value is a valid angle (0.0 to 360.0).

# Safity checks
# Password strength calculation criteria include: Length (max 5 points, +1 every 2 characters),
# presence of uppercase letters (+1), lowercase letters (+1), numbers (+1), special characters (+1),
# spaces (+1), and penalties for consecutive sequences of uppercase, lowercase, or
# numbers (-0.5 each), repetitive sequences (-0.75 each), common weak passwords like "qwerty",
# and passwords under 6 characters (-2). Adjust scores to a 0 to 10 scale, with a minimum score of 0.
password_strength_min: 1 # x >= 1
password_strength_greater: 2 # x > 2
password_strength_not: 0 # x != 0
password_strength: 7 # x == 7
password_strength_less: 8 # x < 8
password_strength_max: 9 # x <= 9
is_password_safe_chars: true # Check that the cell value contains only safe characters for regular passwords. Allowed characters: a-z, A-Z, 0-9, !@#$%^&*()_+-=[]{};:'"|,.<>/?~.

# Internet
is_ip: true # Both: IPv4 or IPv6.
is_ip_v4: true # Only IPv4. Example: "127.0.0.1".
Expand Down
8 changes: 8 additions & 0 deletions schema-examples/full_clean.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ columns:
is_base64: true
is_angle: true

password_strength_min: 1
password_strength_greater: 2
password_strength_not: 0
password_strength: 7
password_strength_less: 8
password_strength_max: 9
is_password_safe_chars: true

is_ip: true
is_ip_v4: true
is_ip_v6: true
Expand Down
Loading

0 comments on commit 80191ad

Please sign in to comment.