forked from appdev-projects/ruby-sandbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnone_shall_pass.rb
119 lines (97 loc) · 2.6 KB
/
none_shall_pass.rb
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
EMAIL = "[email protected]"
PASSWORD = "gocode"
PASSWORD_VAULT = {aws: {username: "jess", password: "jno"}}
def welcome_message
puts "Welcome to None Shall Pass - A Password Manager"
end
def prompt_user_for_email
puts "Please sign in to continue"
print "Enter email: "
gets.chomp
end
def verify_user_email(user_email)
if user_email != EMAIL
puts "Invalid Email"
exit
end
end
def prompt_user_for_password
print "Enter password: "
gets.chomp
end
def verify_user_password(user_password)
if user_password != PASSWORD
puts "Invalid Password"
exit
end
end
def greet_user(user_email)
puts "Hello, #{user_email}"
puts "What would you like to do?"
end
def menu_options
puts "1. Add new service credentials"
puts "2. Retrieve an existing services credentials"
puts "3. Exit"
end
def get_user_menu_selection
gets.chomp
end
def handle_user_selection(user_selection)
case user_selection
when "1"
new_service = set_new_service_name
set_username_for(new_service)
set_password_for(new_service)
when "2"
requested_service_name = retrieve_service_name
credentials = retrieve_service_credentials_for(requested_service_name)
display_service_credentials(requested_service_name, credentials)
else
exit_program
end
end
def set_new_service_name
print "Enter the name of the service: "
new_service = gets.chomp
PASSWORD_VAULT[new_service.to_sym] = {}
new_service
end
def set_username_for(service)
print "Enter the username for this new service: "
new_service_username = gets.chomp
PASSWORD_VAULT[service.to_sym][:username] = new_service_username
end
def set_password_for(service)
print "Enter the password name for this new service: "
new_service_password = gets.chomp
PASSWORD_VAULT[service.to_sym][:password] = new_service_password
end
def retrieve_service_name
print "Please enter the name of the service you wish to access credentials for: "
gets.chomp
end
def retrieve_service_credentials_for(service_name)
PASSWORD_VAULT[service_name.to_sym]
end
def display_service_credentials(service_name, credentials)
puts "Here are the credentials for #{service_name}:"
credentials.each do |key, val|
puts "#{key}: #{val}"
end
end
def exit_program
puts "Exiting the PROGRAM"
exit
end
welcome_message
user_email = prompt_user_for_email
verify_user_email(user_email)
user_password = prompt_user_for_password
verify_user_password(user_password)
greet_user(user_email)
loop do
menu_options
user_selection = get_user_menu_selection
handle_user_selection(user_selection)
end