Advertisement
Guest User

Untitled

a guest
Sep 27th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. /// <summary>
  2. /// Checks if the given username and password match.
  3. /// </summary>
  4. /// <param name="username">Username.</param>
  5. /// <param name="password">Password.</param>
  6. /// <returns>User if login was successful, null otherwise.</returns>
  7. public User GetUser(string username, string password)
  8. {
  9. string sql = @"
  10. SELECT id, name, username, money FROM Users
  11. WHERE username = @username
  12. AND password = @password
  13. ";
  14.  
  15. SQLiteCommand cmd = new SQLiteCommand(sql, connection);
  16.  
  17. cmd.Parameters.AddWithValue("@username", username);
  18. cmd.Parameters.AddWithValue("@password", password);
  19.  
  20. SQLiteDataReader reader = cmd.ExecuteReader();
  21.  
  22. User user = null;
  23.  
  24. if (reader.Read())
  25. {
  26. user = new User(
  27. (long) reader["id"],
  28. (string) reader["name"],
  29. (string) reader["username"],
  30. (double) reader["money"],
  31. new List<Diginote>()
  32. );
  33.  
  34. sql = @"
  35. SELECT id
  36. FROM Diginotes
  37. WHERE Diginotes.userId = @userId
  38. ";
  39.  
  40. cmd = new SQLiteCommand(sql, connection);
  41.  
  42. cmd.Parameters.AddWithValue("@userId", user.Id);
  43.  
  44. reader = cmd.ExecuteReader();
  45.  
  46. while (reader.Read())
  47. {
  48. user.Wallet.Add(new Diginote((long) reader["id"]));
  49. }
  50. }
  51.  
  52. return user;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement