50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/ree_lib/packages/ree_validator/package/ree_validator/functions/validate_password.rb', line 50
def call(password, error = nil, **opts)
opts = DEFAULTS.merge(opts)
if opts[:max_length]
validate_length(
password,
error || PasswordErr.new(
t(
"validator.password.max_password_length",
{number: opts[:max_length]},
default_by_locale: :en
)
),
max: opts[:max_length]
)
end
validate_length(
password,
error || PasswordErr.new(
t(
"validator.password.min_password_length",
{number: opts[:min_length]},
default_by_locale: :en
)
),
min: opts[:min_length]
)
if !password.match?(/\A(?=.*\d{#{opts[:digit_count]},})/x)
error ||= PasswordErr.new(
t(
"validator.password.wrong_number_of_digits",
{number: opts[:digit_count]},
default_by_locale: :en
)
)
raise error
end
if !password.match?(/\A(?=.*[a-z]{#{opts[:lowercase_char_count]},})/x)
error ||= PasswordErr.new(
t(
"validator.password.wrong_number_of_lowercase_chars",
{number: opts[:lowercase_char_count]},
default_by_locale: :en
)
)
raise error
end
if !password.match?(/\A(?=.*[A-Z]{#{opts[:uppercase_char_count]},})/x)
error ||= PasswordErr.new(
t(
"validator.password.wrong_number_of_uppercase_chars",
{number: opts[:uppercase_char_count]},
default_by_locale: :en
)
)
raise error
end
if !password.match?(/\A(?=.*[[:^alnum:]]{#{opts[:special_symbol_count]},})/x)
error ||= PasswordErr.new(
t(
"validator.password.wrong_number_of_special_symbols",
{number: opts[:special_symbol_count]},
default_by_locale: :en
)
)
raise error
end
true
end
|