#3928 Zxcvbn service to compute password complexity

This commit is contained in:
maatinito 2019-06-19 12:30:49 -10:00 committed by Pierre de La Morinerie
parent 3703a71ea3
commit 0b0ef8a318
3 changed files with 26 additions and 6 deletions

View file

@ -0,0 +1,23 @@
class ZxcvbnService
def initialize(password)
@password = password
end
def complexity
wxcvbn = compute_zxcvbn
score = wxcvbn.score
length = @password.blank? ? 0 : @password.length
vulnerabilities = wxcvbn.match_sequence.map { |m| m.matched_word.nil? ? m.token : m.matched_word }.select { |s| s.length > 2 }.join(', ')
[score, vulnerabilities, length]
end
def score
compute_zxcvbn.score
end
private
def compute_zxcvbn
Zxcvbn.test(@password, [], ZXCVBN_DICTIONNARIES)
end
end