-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.rb
35 lines (28 loc) · 900 Bytes
/
auth.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
users = [
{username: 'deepak', password: 'password1'},
{username: 'deepu', password: 'password2'},
{username: 'dpk', password: 'password3'},
]
puts "welcome to the authenticatior"
def authentication_user(username, password, listOfUsers)
listOfUsers.each do |user|
if user[:username] == username && user[:password] == password
return user
end
end
#no need to write the return in the end
"Credentials were not correct"
end
attempt = 1
while attempt < 3
print "usernames: "
username = gets.chomp
print "password: "
password = gets.chomp
p authentication_user(username, password, users)
p "Press n to quit or any other key to continue: "
input = gets.chomp.downcase
break if input == 'n'
attempt += 1
end
p "you have exceeded the number of attempts" if attempt == 3