2019-06-20 00:30:49 +02:00
|
|
|
class ZxcvbnService
|
|
|
|
def initialize(password)
|
|
|
|
@password = password
|
|
|
|
end
|
|
|
|
|
|
|
|
def complexity
|
|
|
|
wxcvbn = compute_zxcvbn
|
|
|
|
score = wxcvbn.score
|
|
|
|
length = @password.blank? ? 0 : @password.length
|
2019-09-12 11:26:22 +02:00
|
|
|
vulnerabilities = wxcvbn.match_sequence.map { |m| m.matched_word.nil? ? m.token : m.matched_word }.filter { |s| s.length > 2 }.join(', ')
|
2019-06-20 00:30:49 +02:00
|
|
|
[score, vulnerabilities, length]
|
|
|
|
end
|
|
|
|
|
|
|
|
def score
|
|
|
|
compute_zxcvbn.score
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def compute_zxcvbn
|
|
|
|
Zxcvbn.test(@password, [], ZXCVBN_DICTIONNARIES)
|
|
|
|
end
|
|
|
|
end
|