FRMPswdChngeF.cpp 9.8 KB

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