46
47
48
49
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
# File 'app/services/lesli_shield/user_validator_service.rb', line 46
def password_complexity(password)
if password.blank?
failures.push('error_password_cannot_be_blank')
return self
end
password_string_no_special = password.gsub(/[^0-9A-Za-z]/, '')
password_values = [
'password_expiration_time_days',
'password_enforce_complexity',
'password_special_char_count',
'password_lowercase_count',
'password_uppercase_count',
'password_minimum_length',
'password_digit_count'
].map do |setting_name|
"name = '#{setting_name}'"
end
password_settings = []
if @resource.account
password_settings = @resource.account.settings.where(password_values.join(" or "))
elseif Account.first
password_settings = Account.first.settings.where(password_values.join(" or "))
end
password_settings.each do |settings|
if settings[:name] == 'password_enforce_complexity' && settings[:value] != "1"
failures = []
break
end
if settings[:name] == 'password_special_char_count'
if settings[:value].to_i > password.scan(/[^0-9A-Za-z]/).length
failures.push('error_password_special_char_count')
end
end
if settings[:name] == 'password_lowercase_count'
if settings[:value].to_i > password_string_no_special.scan(/[^0-9A-Z]/).length
failures.push('error_password_lowercase_count')
end
end
if settings[:name] == 'password_uppercase_count'
if settings[:value].to_i > password_string_no_special.scan(/[^0-9a-z]/).length
failures.push('error_password_uppercase_count')
end
end
if settings[:name] == 'password_digit_count'
if settings[:value].to_i > password_string_no_special.scan(/[^A-Za-z]/).length
failures.push('error_password_digit_count')
end
end
if settings[:name] == 'password_minimum_length'
if settings[:value].to_i > password.length
failures.push('error_password_minimum_length')
end
end
end
return self
end
|