Password.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //---------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <assert.h>
  5. #include <VCLCommon.h>
  6. #include <TextsWin.h>
  7. #include "Password.h"
  8. //---------------------------------------------------------------------
  9. #pragma link "PasswordEdit"
  10. #pragma resource "*.dfm"
  11. //---------------------------------------------------------------------
  12. bool __fastcall DoPasswordDialog(const AnsiString Caption,
  13. TPasswordKind Kind, AnsiString &Password)
  14. {
  15. bool Result = false;
  16. TPasswordDialog * PasswordDialog = new TPasswordDialog(Application);
  17. try
  18. {
  19. PasswordDialog->PasswordCaption = Caption;
  20. PasswordDialog->Password = "";
  21. PasswordDialog->Kind = Kind;
  22. Result = (bool)(PasswordDialog->ShowModal() == mrOk);
  23. if (Result)
  24. {
  25. Password = PasswordDialog->Password;
  26. }
  27. }
  28. __finally
  29. {
  30. delete PasswordDialog;
  31. }
  32. return Result;
  33. }
  34. //---------------------------------------------------------------------
  35. __fastcall TPasswordDialog::TPasswordDialog(TComponent* AOwner)
  36. : TForm(AOwner)
  37. {
  38. UseSystemSettings(this);
  39. Kind = pkPassword;
  40. }
  41. //---------------------------------------------------------------------
  42. void __fastcall TPasswordDialog::SetPasswordCaption(const AnsiString value)
  43. {
  44. PasswordLabel->Caption = value;
  45. }
  46. //---------------------------------------------------------------------
  47. AnsiString __fastcall TPasswordDialog::GetPasswordCaption()
  48. {
  49. return PasswordLabel->Caption;
  50. }
  51. //---------------------------------------------------------------------
  52. void __fastcall TPasswordDialog::SetPassword(const AnsiString value)
  53. {
  54. PasswordEdit->Text = value;
  55. }
  56. //---------------------------------------------------------------------
  57. AnsiString __fastcall TPasswordDialog::GetPassword()
  58. {
  59. return PasswordEdit->Text;
  60. }
  61. //---------------------------------------------------------------------
  62. void __fastcall TPasswordDialog::SetKind(TPasswordKind value)
  63. {
  64. FKind = value;
  65. int Title;
  66. switch (Kind) {
  67. case pkPassword: Title = PASSWORD_TITLE; break;
  68. case pkPassphrase: Title = PASSPHRASE_TITLE; break;
  69. case pkServerPrompt: Title = SERVER_PASSWORD_TITLE; break;
  70. default: assert(false);
  71. }
  72. Caption = LoadStr(Title);
  73. bool ShowServerPanel = (Kind == pkServerPrompt);
  74. if (ShowServerPanel != ServerPromptPanel->Visible)
  75. {
  76. ServerPromptPanel->Visible = ShowServerPanel;
  77. ClientHeight += (ShowServerPanel ? 1 : -1) * ServerPromptPanel->Height;
  78. }
  79. }
  80. //---------------------------------------------------------------------------
  81. void __fastcall TPasswordDialog::HideTypingCheckClick(TObject * /*Sender*/)
  82. {
  83. PasswordEdit->Password = HideTypingCheck->Checked;
  84. }
  85. //---------------------------------------------------------------------------