FRMPswdChngeF.cpp 8.2 KB

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