UserCollection.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* Copyright (C) 2014 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
  2. *
  3. * You can redistribute this program and/or modify it under the terms of
  4. * the GNU Lesser Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. */
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Text;
  10. namespace SMBLibrary.Server
  11. {
  12. public class UserCollection : List<User>
  13. {
  14. public void Add(string accountName, string password)
  15. {
  16. Add(new User(accountName, password));
  17. }
  18. public int IndexOf(string accountName)
  19. {
  20. for (int index = 0; index < this.Count; index++)
  21. {
  22. if (string.Equals(this[index].AccountName, accountName, StringComparison.InvariantCultureIgnoreCase))
  23. {
  24. return index;
  25. }
  26. }
  27. return -1;
  28. }
  29. public string GetUserPassword(string accountName)
  30. {
  31. int index = IndexOf(accountName);
  32. if (index >= 0)
  33. {
  34. return this[index].Password;
  35. }
  36. return null;
  37. }
  38. public List<string> ListUsers()
  39. {
  40. List<string> result = new List<string>();
  41. foreach (User user in this)
  42. {
  43. result.Add(user.AccountName);
  44. }
  45. return result;
  46. }
  47. }
  48. }