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

Last change on this file since 33 was 33, checked in by cheese, 8 years ago
  1. 클라이언트 UI ID/PW 입력 안하면 죽는 문제 수정
  2. UI 종료 함수 exit로 수정
  3. 그룹챗 인덱스 변수 형 때문에 나오는 warning 수정
  4. toOpenSession 함수 가끔 죽는 문제 수정
  5. generateRandom()에서 time()하던거 rand()로 수정
  6. sms 전송 url 및 sms 코드 생성 로직 대폭 수정 (주석 참고)
File size: 2.2 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 if (id == _T(""))
62 {
63 AfxMessageBox(_T("No ID"));
64 return;
65 }
66
67 std::string name = cf::codec::hex::getInstance()->encode(c.sha256(cf::bin(cstr2str(id))));
68 std::ifstream f(name);
69 if(!f)
70 {
71 AfxMessageBox(_T("FILE OPEN FAILED ( LOGIN )"));
72 EndDialog(1);
73 }
74
75 this->mId = cstr2str(id);
76
77 GetDlgItemText(IDC_EDIT_LOGIN_PW, pw);
78 if (pw == _T(""))
79 {
80 AfxMessageBox(_T("No Password"));
81 return;
82 }
83
84 f >> str;
85
86 try
87 {
88 decoded = cf::codec::hex::getInstance()->decode(str);
89
90 c.setKey(cf::bin(cstr2str(pw)));
91 str = c.decrypt(decoded).toString();
92 }
93 catch(cf::exception &e)
94 {
95 AfxMessageBox(_T("Invalid Password"));
96 (void)e;
97 return;
98 }
99
100 if (str.size() == 6)
101 {
102 for (size_t iter = 0; iter < str.size(); iter++)
103 {
104 if (!(str[iter] >= '0' && str[iter] <= '9'))
105 {
106 AfxMessageBox(_T("Decrypt Error"));
107 EndDialog(2);
108 }
109 }
110 }
111 else
112 {
113 AfxMessageBox(_T("Decrypt Error"));
114 EndDialog(3);
115 }
116
117 if (!chev->login(cstr2str(id), cstr2str(pw), str))
118 AfxMessageBox(_T("Login Failed"));
119 else
120 EndDialog(0);
121}
Note: See TracBrowser for help on using the repository browser.