PassWord.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // PassWord.cpp : 实现文件
  2. //
  3. #include "stdafx.h"
  4. #include "RandomKey.h"
  5. #include "PassWord.h"
  6. // CPassWord 对话框
  7. IMPLEMENT_DYNAMIC(CPassWord, CDialog)
  8. CPassWord::CPassWord(CWnd* pParent /*=NULL*/)
  9. : CDialog(CPassWord::IDD, pParent)
  10. , edit1(_T(""))
  11. , edit2(_T(""))
  12. , edit3(_T(""))
  13. {
  14. }
  15. CPassWord::~CPassWord()
  16. {
  17. }
  18. void CPassWord::DoDataExchange(CDataExchange* pDX)
  19. {
  20. CDialog::DoDataExchange(pDX);
  21. DDX_Text(pDX, IDC_EDIT1, edit1);
  22. DDX_Text(pDX, IDC_EDIT2, edit2);
  23. DDX_Text(pDX, IDC_EDIT3, edit3);
  24. }
  25. BEGIN_MESSAGE_MAP(CPassWord, CDialog)
  26. ON_BN_CLICKED(IDOK, &CPassWord::OnBnClickedOk)
  27. END_MESSAGE_MAP()
  28. // CPassWord 消息处理程序
  29. void CPassWord::OnBnClickedOk()
  30. {
  31. UpdateData(TRUE);
  32. CString szText;
  33. CStdioFile sFile( "./code.txt", CStdioFile::modeRead);
  34. sFile.ReadString(szText);
  35. sFile.Close();
  36. szText = Dectypt(szText);
  37. if (edit1 != szText)
  38. {
  39. MessageBox(" 密码错误! ");
  40. return;
  41. }
  42. if (edit2 != "" && edit2 == edit3)
  43. {
  44. FILE* pFile = fopen("./code.txt","w+");
  45. if (pFile)
  46. {
  47. CString szRet = Encrypt(edit2);
  48. fwrite(szRet,sizeof(char),szRet.GetLength(),pFile);
  49. fclose(pFile);
  50. MessageBox(" 修改密码成功 ");
  51. OnCancel();
  52. }
  53. }
  54. else
  55. {
  56. if (edit2 == "")
  57. {
  58. MessageBox(" 请输入新密码! ");
  59. }
  60. else
  61. {
  62. MessageBox(" 新密码输入不一致! ");
  63. }
  64. }
  65. }