DebugUsers.pas 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. unit DebugUsers;
  2. interface
  3. uses
  4. Classes;
  5. type
  6. TUserInfo = class
  7. private
  8. FUser: string;
  9. FPassword: string;
  10. public
  11. constructor Create(const AUser, APassword: string);
  12. end;
  13. TDebugUsers = class
  14. private
  15. FUsers: TList;
  16. procedure LoadPasswords(const AFileName: string);
  17. public
  18. constructor Create;
  19. destructor Destroy; override;
  20. function GetPassword(const AUser: string): string;
  21. end;
  22. function GetDebugUsers: TDebugUsers;
  23. implementation
  24. uses
  25. UtilMethods, SysUtils, Math;
  26. var
  27. _DebugUsers: TDebugUsers;
  28. function GetDebugUsers: TDebugUsers;
  29. begin
  30. if not Assigned(_DebugUsers) then
  31. _DebugUsers := TDebugUsers.Create;
  32. Result := _DebugUsers;
  33. end;
  34. { TDebugUsers }
  35. constructor TDebugUsers.Create;
  36. var
  37. sFileName: string;
  38. begin
  39. FUsers := TList.Create;
  40. sFileName := GetAppFilePath + 'UserPassword.txt';
  41. LoadPasswords(sFileName);
  42. end;
  43. destructor TDebugUsers.Destroy;
  44. begin
  45. FUsers.Free;
  46. inherited;
  47. end;
  48. function TDebugUsers.GetPassword(const AUser: string): string;
  49. var
  50. i: Integer;
  51. vUser: TUserInfo;
  52. begin
  53. Result := '';
  54. for i := 0 to FUsers.Count - 1 do
  55. begin
  56. vUser := TUserInfo(FUsers.Items[i]);
  57. if (vUser.FUser = AUser) then
  58. begin
  59. Result := vUser.FPassword;
  60. Break;
  61. end;
  62. end;
  63. end;
  64. procedure TDebugUsers.LoadPasswords(const AFileName: string);
  65. var
  66. sgs: TStrings;
  67. i, iPos: Integer;
  68. sValue, sUser, sPassword: string;
  69. vUser: TUserInfo;
  70. begin
  71. if FileExists(AFileName) then
  72. begin
  73. sgs := TStringList.Create;
  74. try
  75. sgs.LoadFromFile(AFileName);
  76. for i := 0 to sgs.Count - 1 do
  77. begin
  78. sValue := sgs.Strings[i];
  79. iPos := Pos(';', sValue);
  80. if iPos > 0 then
  81. begin
  82. sUser := Copy(sValue, 1, iPos - 1);
  83. sPassword := Copy(sValue, iPos + 1, Length(sValue)-iPos);
  84. vUser := TUserInfo.Create(sUser, sPassword);
  85. FUsers.Add(vUser);
  86. end;
  87. end;
  88. finally
  89. sgs.Free;
  90. end;
  91. end;
  92. end;
  93. { TPassword }
  94. constructor TUserInfo.Create(const AUser, APassword: string);
  95. begin
  96. FUser := AUser;
  97. FPassword := APassword;
  98. end;
  99. initialization
  100. finalization
  101. _DebugUsers.Free;
  102. end.