10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/koodmeeter/core.rb', line 10
def check(password, minimum_chars = DEFAULT_MIN_CHARS)
password = password.to_s
raise ArgumentError.new 'Password argument required!' if password.nil?
return 0 unless blacklist.index(password).nil?
length = password.length
diff = length - minimum_chars
scores_dupe = @@scores.dup
score = calculate_diff_increment(diff)
Axiom.list.each do |axiom|
if axiom[:regex].match(password)
score += axiom[:score]
end
end
score += length
if score < 0 && score > -199
index = 0
else
scores_dupe.push(score).sort!
index = scores_dupe.index(score) + 1
end
return LEVELS[index].nil? ? LEVELS.last : LEVELS[index]
end
|