users = [
{username: "mashrur", password: "password1"},
{username: "jack", password: "password2"},
{username: "arya", password: "password3"},
{username: "jonshow", password: "password4"},
{username: "heisenberg", password: "password5"}
]
def auth_user(username, password, users)
users.each do |user_record|
if user_record[:username] == username && user_record[:password] == password
return user_record
end
end
"Credentials were not correct"
end
puts "Welcome to the authenticator"
25.times {print "-"}
puts "This program will take the input from the user and compare password"
attempts = 1
while attempts < 4
print "Username:"
username = gets.chomp
print "Password:"
password = gets.chomp
authentication = auth_user(username, password, users)
puts authentication
puts "Press n to quit or any other key to continue"
input = gets.chomp.downcase
break if input == "n"
attempts +=1
end
puts "You have exceeded the number of attempts" if attempts == 4