PasswordStrengthMeter 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/lib/password_strength_meter.rb +110 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZDdjMzAwOGI5MzViYmUwYWMwYjE1YWNjMWEwZGYyMDM5NDkwODYyNw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
Mzc3N2VhYmU5ZjM1MzZjNTk2ODMzNGYwZTdiMDdmNTYyNWMwZDY4OQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZmFjYmRhZmVjMTYwMjEwZmM5YjVlYWFlMzdjODlkNDRjNjM4ZGU5NjZjN2Rm
|
10
|
+
ZDhkOTA1ZjE2YjNhMDk3NTU5Yjk4ODdjZDhkYzZkM2I1ODZhYWVlNDYyNGJj
|
11
|
+
NjhmYTFhMzg2NmY1YzhmNWYzN2QxNTM5MzFlZmY4NGM4NjQ4NDQ=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NzhkNjgzMzljYmE3NjVlYWU1MGI1YTJhNjQ5ZDMyZjI1Y2Q0MGRiN2RkZTFm
|
14
|
+
ZjQ2ZWZjMGQwOGNlZWVjOWE3YTZjNWUzNmY5Y2YzMjY1MjljOTlhOWM4NjFh
|
15
|
+
ODdiZmEyNzgwNDNlOTYyZDlhOWQyYmI0MjJhOWI3NmY5YjVjNTE=
|
@@ -0,0 +1,110 @@
|
|
1
|
+
class PasswordStrengthMeter
|
2
|
+
def self.evaluate(username, password)
|
3
|
+
puntuacion = 1.0
|
4
|
+
if password.match(/[A-Z]/).nil?
|
5
|
+
puntuacion -= 0.2
|
6
|
+
end
|
7
|
+
|
8
|
+
if password.match(/[a-z]/).nil?
|
9
|
+
puntuacion -= 0.2
|
10
|
+
end
|
11
|
+
|
12
|
+
if password.match(/[0-9]/).nil?
|
13
|
+
puntuacion -= 0.1
|
14
|
+
end
|
15
|
+
|
16
|
+
if password.length <= 5
|
17
|
+
puntuacion -= 0.3
|
18
|
+
end
|
19
|
+
|
20
|
+
if password.length <= 7
|
21
|
+
puntuacion -= 0.1
|
22
|
+
v end
|
23
|
+
|
24
|
+
similitud = (1.0 - (PasswordStrengthMeter.jaro_winkler(username, password, true) || 0.0))
|
25
|
+
similitud = 1.0 if similitud.nil? or similitud.nan?
|
26
|
+
|
27
|
+
puts "Score: #{puntuacion.to_s} Similarity: #{similitud.to_s}"
|
28
|
+
|
29
|
+
evaluacion = (puntuacion * similitud)
|
30
|
+
evaluacion = (evaluacion).round(4)
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.jaro_winkler(str1, str2, winkleradjust=false)
|
34
|
+
m = 0
|
35
|
+
tr = 0
|
36
|
+
|
37
|
+
s1 = str1.strip.split(//)
|
38
|
+
s2 = str2.strip.split(//)
|
39
|
+
|
40
|
+
s1l = s1.length
|
41
|
+
s2l = s2.length
|
42
|
+
|
43
|
+
if s1l > s2l
|
44
|
+
tmp = s2
|
45
|
+
s2 = s1
|
46
|
+
s1 = tmp
|
47
|
+
end
|
48
|
+
|
49
|
+
found = Hash[*s2.uniq.sort.collect { |v| [v,0]}.flatten]
|
50
|
+
|
51
|
+
md = (([s1l,s2l].max / 2) - 1).to_i
|
52
|
+
|
53
|
+
s1.each_with_index do |c,i|
|
54
|
+
|
55
|
+
if !found[c].nil?
|
56
|
+
if !s2.aindices(c)[found[c]].nil?
|
57
|
+
x = (s2.aindices(c)[found[c]] - i).abs
|
58
|
+
if x <= md
|
59
|
+
found[c] += 1
|
60
|
+
m += 1
|
61
|
+
if (x != 0)
|
62
|
+
tr += 1
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
tr = (tr/2).to_i
|
69
|
+
|
70
|
+
third = 1.0/3
|
71
|
+
jd = (third * m / s1l) + (third * m / s2l) + (third * (m - tr) / m)
|
72
|
+
out = jd
|
73
|
+
|
74
|
+
if winkleradjust
|
75
|
+
l = 0
|
76
|
+
(0..s1l-1).each { |i| s1[i]==s2[i] ? l+=1 : break }
|
77
|
+
out = jd + (l * 0.1 * (1 - jd))
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
class String
|
87
|
+
def each_char_with_index
|
88
|
+
i = 0
|
89
|
+
split(//).each do |c|
|
90
|
+
yield i, c
|
91
|
+
i += 1
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
class Array
|
97
|
+
def select_with_index
|
98
|
+
index = -1
|
99
|
+
select { |x| index += 1; yield(x, index) }
|
100
|
+
end
|
101
|
+
|
102
|
+
def aindices(o)
|
103
|
+
out = Array.new
|
104
|
+
select_with_index { |x, i|
|
105
|
+
out << i if x == o }
|
106
|
+
out
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: PasswordStrengthMeter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adrian Fernandez Lopez
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-03 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Evaluate password strength
|
14
|
+
email: adrian@adrian-fernandez.net
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/password_strength_meter.rb
|
20
|
+
homepage: https://github.com/adrian-fernandez/password_strength_meter
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.2.2
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Evaluate password strength
|
44
|
+
test_files: []
|
45
|
+
has_rdoc:
|