FRMPswdChngeF.cpp 11 KB

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