Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

Ruby Multi User Login

By: a guest on Feb 5th, 2013  |  syntax: Ruby  |  size: 0.96 KB  |  hits: 24  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  
  2. # Structure      Username     Password   Age        Email
  3. users_array = [["username1", "password1", 19, "email@gmail.com"],
  4.                            ["myuser2","mypass2",21,"Awesome.ninja@aol.co.uk"],
  5.                            ["Mr. P-teo", "secretPass", 23, "hidden_email@gmail.com"]]
  6.                            
  7. user_array_rows = users_array.length
  8.  
  9. #input
  10.  
  11. print "Username: "
  12. user_name = gets.chomp!
  13.  
  14. print "Password: "
  15. user_password = gets.chomp!
  16.  
  17. if(user_name.length > 0 && user_password.length > 0)
  18.         #move on to user validation
  19.        
  20.         count = 0      
  21.         #check user and pass agains stored user pass combos
  22.         while count <= user_array_rows
  23.                 if(user_name == users_array[count][0] && user_password == users_array[count][1])
  24.                         count = user_array_rows + 1
  25.                         puts "Welcome to your account #{user_name}"
  26.                         logged_in = true
  27.                 end
  28.                 count += 1
  29.         end
  30.         #Check if logged in
  31.         if(!logged_in)
  32.                 puts "Login attempt unsuccessful!"
  33.         end
  34. else
  35.         #no use or pass entered.
  36.         puts "Remember to enter both the username and password"
  37. end