FRMPswdChngeF.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include "AppGlobalF.h"
  4. #include "ITSUtilF.h"
  5. #include "ITSDbF.h"
  6. //#include "EncryptionF.h"
  7. #pragma hdrstop
  8. #include "FrmPswdChngeF.h"
  9. #include "FrmLoginF.h"
  10. //---------------------------------------------------------------------------
  11. #pragma package(smart_init)
  12. #pragma link "cxButtons"
  13. #pragma link "cxGraphics"
  14. #pragma link "cxLookAndFeelPainters"
  15. #pragma link "cxLookAndFeels"
  16. #pragma link "dxSkinBlack"
  17. #pragma link "dxSkinBlue"
  18. #pragma link "dxSkinCaramel"
  19. #pragma link "dxSkinCoffee"
  20. #pragma link "dxSkinDarkRoom"
  21. #pragma link "dxSkinDarkSide"
  22. #pragma link "dxSkinFoggy"
  23. #pragma link "dxSkinGlassOceans"
  24. #pragma link "dxSkiniMaginary"
  25. #pragma link "dxSkinLilian"
  26. #pragma link "dxSkinLiquidSky"
  27. #pragma link "dxSkinLondonLiquidSky"
  28. #pragma link "dxSkinMcSkin"
  29. #pragma link "dxSkinMoneyTwins"
  30. #pragma link "dxSkinOffice2007Black"
  31. #pragma link "dxSkinOffice2007Blue"
  32. #pragma link "dxSkinOffice2007Green"
  33. #pragma link "dxSkinOffice2007Pink"
  34. #pragma link "dxSkinOffice2007Silver"
  35. #pragma link "dxSkinOffice2010Black"
  36. #pragma link "dxSkinOffice2010Blue"
  37. #pragma link "dxSkinOffice2010Silver"
  38. #pragma link "dxSkinsCore"
  39. #pragma link "dxSkinSeven"
  40. #pragma link "dxSkinSharp"
  41. #pragma link "dxSkinSilver"
  42. #pragma link "dxSkinStardust"
  43. #pragma resource "*.dfm"
  44. TFRMPswdChnge *FRMPswdChnge = NULL;
  45. //---------------------------------------------------------------------------
  46. __fastcall TFRMPswdChnge::TFRMPswdChnge(TComponent* Owner)
  47. : TForm(Owner)
  48. {
  49. //ITSSkin_Load(this);
  50. }
  51. //---------------------------------------------------------------------------
  52. /*
  53. * 사용자가 비밀번호 변경을 요청함.
  54. * parameter
  55. * return
  56. *
  57. */
  58. void __fastcall TFRMPswdChnge::btnPswdChngeClick(TObject *Sender)
  59. {
  60. if (!ValidateInputField())
  61. return;
  62. int nRes;
  63. nRes = FRMLogin->GetUserPassword(EdUserID->Text, EdPswd->Text);
  64. if (LOGIN_DB_ERR == nRes)
  65. {
  66. return;
  67. }
  68. if (LOGIN_ID_ERR == nRes)
  69. {
  70. Application->NormalizeTopMosts();
  71. if (g_AppCfg.sLang == "kr") Application->MessageBox(L"등록되지 않은 사용자 입니다.", L"아이디 오류", MB_OK|MB_ICONERROR); // 등록되지 않은 사용자 입니다.
  72. else Application->MessageBox(L"Unregistered user.", L"User ID Error", MB_OK|MB_ICONERROR); // 등록되지 않은 사용자 입니다.
  73. Application->RestoreTopMosts();
  74. EdUserID->SetFocus();
  75. return;
  76. }
  77. if (LOGIN_PSWD_ERR == nRes)
  78. {
  79. Application->NormalizeTopMosts();
  80. if (g_AppCfg.sLang == "kr") Application->MessageBox(L"비밀번호가 일치하지 않습니다.", L"비밀번호 오류", MB_OK|MB_ICONERROR); // 비밀번호가 일치하지 않습니다.
  81. else Application->MessageBox(L"Passwords do not match.", L"Password Error", MB_OK|MB_ICONERROR); // 비밀번호가 일치하지 않습니다.
  82. Application->RestoreTopMosts();
  83. EdPswd->SetFocus();
  84. return;
  85. }
  86. EdUserID->Text = EdUserID->Text.Trim();
  87. EdCnfmNewPswd->Text = EdCnfmNewPswd->Text.Trim();
  88. if (EdNewPswd->Text == EdPswd->Text)
  89. {
  90. Application->NormalizeTopMosts();
  91. if (g_AppCfg.sLang == "kr") Application->MessageBox(L"기존 비밀번호와 신규로 입력한 비밀번호가 일치합니다.\r\n새로운 비밀번호를 입력하세요.", L"비밀번호 변경 오류", MB_OK|MB_ICONERROR);
  92. else Application->MessageBox(L"Your old and new passwords match.\r\nEnter a new password.", L"Password change error", MB_OK|MB_ICONERROR);
  93. Application->RestoreTopMosts();
  94. EdNewPswd->SetFocus();
  95. return;
  96. }
  97. int nResult = UpdateUserPassword(EdUserID->Text.Trim(), EdCnfmNewPswd->Text.Trim());
  98. if (nResult > 0)
  99. {
  100. Application->NormalizeTopMosts();
  101. if (g_AppCfg.sLang == "kr") Application->MessageBox(L"비밀번호가 변경되었습니다.", L"비밀번호 변경 확인", MB_OK); // 비밀번호가 변경되었습니다. , 확인
  102. else Application->MessageBox(L"Password changed.", L"Confirm password change", MB_OK); // 비밀번호가 변경되었습니다. , 확인
  103. Application->RestoreTopMosts();
  104. }
  105. Close();
  106. }
  107. //---------------------------------------------------------------------------
  108. /*
  109. * 사용자 아이디에 해당하는 비밀번호를 변경한다.
  110. * parameter
  111. * strUserID : 사용자 ID
  112. * strNewPswd : 변경한 새로운 비밀번호
  113. * return
  114. *
  115. */
  116. int __fastcall TFRMPswdChnge::UpdateUserPassword(String sUserID, String sNewPswd)
  117. {
  118. String sQry;
  119. TADOQuery *adoQry = NULL;
  120. #if 0
  121. sQry= "UPDATE TB_USER_INFR \r\n"
  122. " SET PWD = SCP.HASH_B64('71', :p01) \r\n"
  123. " WHERE USER_ID = :p02 \r\n";
  124. #else
  125. sQry= "UPDATE TB_USER_INFR \r\n"
  126. " SET PWD = :p01 \r\n"
  127. " WHERE USER_ID = :p02 \r\n";
  128. #endif
  129. try
  130. {
  131. try
  132. {
  133. adoQry = new TADOQuery(NULL);
  134. adoQry->Connection = ITSDb_GetConnection();
  135. ITSDb_GetConnection()->BeginTrans();
  136. adoQry->Close();
  137. adoQry->SQL->Text = sQry;
  138. adoQry->Parameters->ParamByName("p01")->Value = sNewPswd;
  139. adoQry->Parameters->ParamByName("p02")->Value = sUserID;
  140. int nRowCnt = adoQry->ExecSQL();
  141. //ShowMessage(String(nRowCnt));
  142. ITSDb_GetConnection()->CommitTrans();
  143. return nRowCnt;
  144. }
  145. catch (Exception &exception)
  146. {
  147. ITSDb_GetConnection()->RollbackTrans();
  148. throw Exception(String(exception.ClassName()) + exception.Message);
  149. }
  150. catch (...)
  151. {
  152. ITSDb_GetConnection()->RollbackTrans();
  153. }
  154. }
  155. __finally
  156. {
  157. if (adoQry)
  158. {
  159. adoQry->Close();
  160. delete adoQry;
  161. }
  162. }
  163. return -1;
  164. }
  165. //---------------------------------------------------------------------------
  166. /*
  167. * 비밀번호 입력전에 사용자가 입력하여야 할 항목이 입력되어 있는지를 확인한다.
  168. * parameter
  169. * return
  170. *
  171. */
  172. bool __fastcall TFRMPswdChnge::ValidateInputField(void)
  173. {
  174. if (0 == EdUserID->Text.Trim().Length())
  175. {
  176. Application->NormalizeTopMosts();
  177. if (g_AppCfg.sLang == "kr") Application->MessageBox(L"아이디를 입력하십시요.", L"아이디 입력 오류", MB_OK|MB_ICONERROR); // ID를 입력하세요. , 확 인
  178. else Application->MessageBox(L"Please enter User ID.", L"Error entering User ID", MB_OK|MB_ICONERROR); // ID를 입력하세요. , 확 인
  179. Application->RestoreTopMosts();
  180. EdUserID->SetFocus();
  181. return false;
  182. }
  183. if (0 == EdPswd->Text.Trim().Length())
  184. {
  185. Application->NormalizeTopMosts();
  186. if (g_AppCfg.sLang == "kr") Application->MessageBox(L"현재 비밀번호를 입력하십시요.", L"비밀번호 입력 오류", MB_OK|MB_ICONERROR); // 현재 비밀번호를 입력하십시요. 확인
  187. else Application->MessageBox(L"Please enter your current password.", L"Error entering User Password", MB_OK|MB_ICONERROR); // 현재 비밀번호를 입력하십시요. 확인
  188. Application->RestoreTopMosts();
  189. EdPswd->SetFocus();
  190. return false;
  191. }
  192. if (0 == EdNewPswd->Text.Trim().Length())
  193. {
  194. Application->NormalizeTopMosts();
  195. if (g_AppCfg.sLang == "kr") Application->MessageBox(L"신규 비밀번호를 입력하십시요.", L"신규 비밀번호 입력 오류", MB_OK|MB_ICONERROR); // 새로운 비밀번호를 입력하십시요. 확인
  196. else Application->MessageBox(L"Please enter your new password.", L"Error entering New Password", MB_OK|MB_ICONERROR); // 새로운 비밀번호를 입력하십시요. 확인
  197. Application->RestoreTopMosts();
  198. EdNewPswd->SetFocus();
  199. return false;
  200. }
  201. if (EdNewPswd->Text != EdCnfmNewPswd->Text)
  202. {
  203. Application->NormalizeTopMosts();
  204. if (g_AppCfg.sLang == "kr") Application->MessageBox(L"신규로 입력한 비밀번호가 일치하지 않습니다.", L"신규 비밀번호 확인 오류", MB_OK|MB_ICONERROR); // 새로 입력한 비밀번호가 일치하지 않습니다. 확인
  205. else Application->MessageBox(L"The newly entered password does not match.", L"New password verification error", MB_OK|MB_ICONERROR); // 새로 입력한 비밀번호가 일치하지 않습니다. 확인
  206. Application->RestoreTopMosts();
  207. EdNewPswd->SetFocus();
  208. return false;
  209. }
  210. return true;
  211. }
  212. //---------------------------------------------------------------------------
  213. /*
  214. * 비밀번호 변경 화면 종료
  215. * parameter
  216. * return
  217. *
  218. */
  219. void __fastcall TFRMPswdChnge::btnCloseClick(TObject *Sender)
  220. {
  221. Close();
  222. }
  223. //---------------------------------------------------------------------------
  224. void __fastcall TFRMPswdChnge::FormCreate(TObject *Sender)
  225. {
  226. SetLocalSkin();
  227. }
  228. //---------------------------------------------------------------------------
  229. /*
  230. * 공통으로 처리되지 않는 스킨을 변경한다.
  231. * arguments
  232. *
  233. * return
  234. * void
  235. */
  236. void __fastcall TFRMPswdChnge::SetLocalSkin()
  237. {
  238. }
  239. //---------------------------------------------------------------------------
  240. /*
  241. * form이 메모리에서 생성될때 호출되는 생성자 파라미터 핸들러
  242. * arguments
  243. * Sender : event handler 객체
  244. * return
  245. * void
  246. */
  247. void __fastcall TFRMPswdChnge::CreateParams(TCreateParams &Params)
  248. {
  249. TForm::CreateParams(Params);
  250. //Params.Style = (Params.Style | WS_POPUP) & ~WS_DLGFRAME; //캡션바 삭제
  251. }
  252. //---------------------------------------------------------------------------
  253. /*
  254. * 캡션타입틀 마우스 클릭시 화면 이동하기
  255. * arguments
  256. *
  257. * return
  258. * void
  259. */
  260. void __fastcall TFRMPswdChnge::ShpCaptionMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
  261. {
  262. ReleaseCapture();
  263. SendMessage(Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0);
  264. }
  265. //---------------------------------------------------------------------------
  266. void __fastcall TFRMPswdChnge::EdUserIDKeyPress(TObject *Sender, wchar_t &Key)
  267. {
  268. if (Key == 13)
  269. {
  270. EdPswd->SetFocus();
  271. }
  272. }
  273. //---------------------------------------------------------------------------
  274. void __fastcall TFRMPswdChnge::EdPswdKeyPress(TObject *Sender, wchar_t &Key)
  275. {
  276. if (Key == 13)
  277. {
  278. EdNewPswd->SetFocus();
  279. }
  280. }
  281. //---------------------------------------------------------------------------
  282. void __fastcall TFRMPswdChnge::EdNewPswdKeyPress(TObject *Sender, wchar_t &Key)
  283. {
  284. if (Key == 13)
  285. {
  286. EdCnfmNewPswd->SetFocus();
  287. }
  288. }
  289. //---------------------------------------------------------------------------
  290. void __fastcall TFRMPswdChnge::EdCnfmNewPswdKeyPress(TObject *Sender, wchar_t &Key)
  291. {
  292. if (Key == 13)
  293. {
  294. BtnConfirm->SetFocus();
  295. }
  296. }
  297. //---------------------------------------------------------------------------