-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPasswordStrength.rb
More file actions
51 lines (44 loc) · 826 Bytes
/
PasswordStrength.rb
File metadata and controls
51 lines (44 loc) · 826 Bytes
1
2
3
4
5
6
7
8
9
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
class PasswordStrength
def check_length(password)
if password.length >= 8
true
else
false
end
end
def check_contains_numbers(password)
if password =~ /\d/
true
else
false
end
end
def check_contains_letters(password)
if password.count("a-zA-Z") > 0
true
else
false
end
end
def evaluate_short_password(password)
if check_contains_letters(password)
"Weak"
else
"Very weak"
end
end
def evaluate_long_password(password)
if check_contains_letters(password) && check_contains_numbers(password)
"Strong"
else
"Weak"
end
end
def answer (password)
if !check_length(password)
evaluate_short_password(password)
else
evaluate_long_password(password)
end
end
end