You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UserPasswdDialog.cxx 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. *
  3. * This is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This software is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this software; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  16. * USA.
  17. */
  18. #include <vncviewer/UserPasswdDialog.h>
  19. #include <vncviewer/resource.h>
  20. #include <rfb/Exception.h>
  21. using namespace rfb;
  22. using namespace rfb::win32;
  23. UserPasswdDialog::UserPasswdDialog() : Dialog(GetModuleHandle(0)),
  24. showUsername(false), showPassword(false) {
  25. }
  26. void UserPasswdDialog::setCSecurity(const CSecurity* cs) {
  27. description.replaceBuf(tstrDup(cs->description()));
  28. }
  29. bool UserPasswdDialog::showDialog() {
  30. return Dialog::showDialog(MAKEINTRESOURCE(IDD_VNC_AUTH_DLG));
  31. }
  32. void UserPasswdDialog::initDialog() {
  33. if (username.buf)
  34. setItemString(IDC_USERNAME, username.buf);
  35. if (password.buf)
  36. setItemString(IDC_PASSWORD, password.buf);
  37. if (!showUsername) {
  38. setItemString(IDC_USERNAME, _T(""));
  39. enableItem(IDC_USERNAME, false);
  40. }
  41. if (!showPassword) {
  42. setItemString(IDC_PASSWORD, _T(""));
  43. enableItem(IDC_PASSWORD, false);
  44. }
  45. if (description.buf) {
  46. TCharArray title(128);
  47. GetWindowText(handle, title.buf, 128);
  48. _tcsncat(title.buf, _T(" ["), 128);
  49. _tcsncat(title.buf, description.buf, 128);
  50. _tcsncat(title.buf, _T("]"), 128);
  51. SetWindowText(handle, title.buf);
  52. }
  53. }
  54. bool UserPasswdDialog::onOk() {
  55. username.replaceBuf(getItemString(IDC_USERNAME));
  56. password.replaceBuf(getItemString(IDC_PASSWORD));
  57. return true;
  58. }
  59. void UserPasswdDialog::getUserPasswd(char** user, char** passwd) {
  60. showUsername = user != 0;
  61. showPassword = passwd != 0;
  62. if (user && *user)
  63. username.replaceBuf(tstrDup(*user));
  64. if (passwd && *passwd)
  65. password.replaceBuf(tstrDup(*passwd));
  66. if (!showDialog())
  67. throw rfb::AuthCancelledException();
  68. if (user)
  69. *user = strDup(username.buf);
  70. if (passwd)
  71. *passwd = strDup(password.buf);
  72. }