FRMPswdChngeF.cpp 11 KB

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