UserCollection.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /* Copyright (C) 2014-2017 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. namespace SMBServer
  10. {
  11. public class UserCollection : List<User>
  12. {
  13. public void Add(string accountName, string password)
  14. {
  15. Add(new User(accountName, password));
  16. }
  17. public int IndexOf(string accountName)
  18. {
  19. for (int index = 0; index < this.Count; index++)
  20. {
  21. if (string.Equals(this[index].AccountName, accountName, StringComparison.OrdinalIgnoreCase))
  22. {
  23. return index;
  24. }
  25. }
  26. return -1;
  27. }
  28. public string GetUserPassword(string accountName)
  29. {
  30. int index = IndexOf(accountName);
  31. if (index >= 0)
  32. {
  33. return this[index].Password;
  34. }
  35. return null;
  36. }
  37. public List<string> ListUsers()
  38. {
  39. List<string> result = new List<string>();
  40. foreach (User user in this)
  41. {
  42. result.Add(user.AccountName);
  43. }
  44. return result;
  45. }
  46. }
  47. }