source: chevmsgr/trunk/msvc14/ChevMsgrClient_MFC/LoginDlg.cpp@ 31

Last change on this file since 31 was 31, checked in by cheese, 8 years ago

키 ㅋ

File size: 2.1 KB
Line 
1// Login.cpp : ±¸Çö ÆÄÀÏÀÔ´Ï´Ù.
2//
3
4#include "stdafx.h"
5#include "ChevMsgrClient_MFC.h"
6#include "LoginDlg.h"
7#include "afxdialogex.h"
8#include "RegisterDlg.h"
9#include "fstream"
10#include "cf/codec.h"
11#include "crypto.h"
12
13
14// CLoginDlg ´ëÈ­ »óÀÚÀÔ´Ï´Ù.
15
16IMPLEMENT_DYNAMIC(CLoginDlg, CDialogEx)
17
18CLoginDlg::CLoginDlg(CWnd* pParent /*=NULL*/)
19 : CDialogEx(IDD_DIALOG_LOGIN, pParent)
20{
21
22}
23
24CLoginDlg::~CLoginDlg()
25{
26}
27
28void CLoginDlg::DoDataExchange(CDataExchange* pDX)
29{
30 CDialogEx::DoDataExchange(pDX);
31}
32
33
34BEGIN_MESSAGE_MAP(CLoginDlg, CDialogEx)
35 ON_BN_CLICKED(IDC_BTN_LOGIN_REGISTER, &CLoginDlg::OnBnClickedBtnLoginRegister)
36 ON_BN_CLICKED(IDC_BTN_LOGIN_LOGIN, &CLoginDlg::OnBnClickedBtnLoginLogin)
37END_MESSAGE_MAP()
38
39
40// CLoginDlg ¸Þ½ÃÁö 󸮱âÀÔ´Ï´Ù.
41
42
43void CLoginDlg::OnBnClickedBtnLoginRegister()
44{
45 // TODO: ¿©±â¿¡ ÄÁÆ®·Ñ ¾Ë¸² 󸮱â Äڵ带 Ãß°¡ÇÕ´Ï´Ù.
46 CRegisterDlg regiDlg;
47 regiDlg.chev = this->chev;
48 regiDlg.DoModal();
49}
50
51
52void CLoginDlg::OnBnClickedBtnLoginLogin()
53{
54 // TODO: ¿©±â¿¡ ÄÁÆ®·Ñ ¾Ë¸² 󸮱â Äڵ带 Ãß°¡ÇÕ´Ï´Ù.
55 CString id, pw;
56 cf::bin decoded;
57 crypto c;
58 std::string str;
59
60 GetDlgItemText(IDC_EDIT_LOGIN_ID, id);
61 std::string name = cf::codec::hex::getInstance()->encode(c.sha256(cf::bin(cstr2str(id))));
62 std::ifstream f(name);
63 if(!f)
64 {
65 AfxMessageBox(_T("FILE OPEN FAILED ( LOGIN )"));
66 EndDialog(1);
67 }
68
69 this->mId = cstr2str(id);
70
71 GetDlgItemText(IDC_EDIT_LOGIN_PW, pw);
72 f >> str;
73
74 try
75 {
76 decoded = cf::codec::hex::getInstance()->decode(str);
77
78 c.setKey(cf::bin(cstr2str(pw)));
79 str = c.decrypt(decoded).toString();
80 }
81 catch(cf::exception &e)
82 {
83 AfxMessageBox(_T("Invalid Password"));
84 (void)e;
85 return;
86 }
87
88 if (str.size() == 6)
89 {
90 for (size_t iter = 0; iter < str.size(); iter++)
91 {
92 if (!(str[iter] >= '0' && str[iter] <= '9'))
93 {
94 AfxMessageBox(_T("Decrypt Error"));
95 EndDialog(2);
96 }
97 }
98 }
99 else
100 {
101 AfxMessageBox(_T("Decrypt Error"));
102 EndDialog(3);
103 }
104
105 if (!chev->login(cstr2str(id), cstr2str(pw), str))
106 AfxMessageBox(_T("Login Failed"));
107 else
108 EndDialog(0);
109}
Note: See TracBrowser for help on using the repository browser.