// DlgLogin.cpp : implementation file // #include "stdafx.h" #include "ReviewRecipeEditor.h" #include "DlgLogin.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CDlgLogin dialog CDlgLogin::CDlgLogin(CWnd* pParent /*=NULL*/) : CDialog(CDlgLogin::IDD, pParent) , m_strEditID(_T("")) , m_strEditCreateID(_T("")) , m_strEditCreatePW(_T("")) , m_strEditCreateCheckPW(_T("")) { //{{AFX_DATA_INIT(CDlgLogin) m_strEditPassword = _T(""); m_strEditNewPwd1 = _T(""); m_strEditNewPwd2 = _T(""); //}}AFX_DATA_INIT m_strOriginPwd = _T(""); m_strID = _T(""); m_nIDCount = 0; m_vecLoginInfo.clear(); m_pFileLog = NULL; m_strLoginLogName = _T(""); m_nLoginLevel = 0; } void CDlgLogin::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CDlgLogin) DDX_Text(pDX, IDC_EDIT_PASSWD, m_strEditPassword); DDV_MaxChars(pDX, m_strEditPassword, 50); DDX_Text(pDX, IDC_EDIT_NEWPASSWD1, m_strEditNewPwd1); DDV_MaxChars(pDX, m_strEditNewPwd1, 50); DDX_Text(pDX, IDC_EDIT_NEWPASSWD2, m_strEditNewPwd2); DDV_MaxChars(pDX, m_strEditNewPwd2, 50); //}}AFX_DATA_MAP DDX_Text(pDX, IDC_EDIT_ID, m_strEditID); DDX_Text(pDX, IDC_EDIT_CREATE_ID, m_strEditCreateID); DDX_Text(pDX, IDC_EDIT_CREATE_PASSWD, m_strEditCreatePW); DDX_Text(pDX, IDC_EDIT_CREATE_CHECK_PASSWD, m_strEditCreateCheckPW); } BEGIN_MESSAGE_MAP(CDlgLogin, CDialog) //{{AFX_MSG_MAP(CDlgLogin) ON_BN_CLICKED(IDC_BUTTON_CHANGE, OnButtonChange) //}}AFX_MSG_MAP ON_BN_CLICKED(IDC_BUTTON_CREATE_ID, &CDlgLogin::OnBnClickedButtonCreateId) ON_BN_CLICKED(IDC_BUTTON_FIND_PASSWORD, &CDlgLogin::OnBnClickedButtonFindPassword) ON_WM_DESTROY() END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CDlgLogin message handlers void CDlgLogin::OnDestroy() { CDialog::OnDestroy(); // TODO: ¿©±â¿¡ ¸Þ½ÃÁö 󸮱â Äڵ带 Ãß°¡ÇÕ´Ï´Ù. ClearLoginInfo(); } void CDlgLogin::ClearLoginInfo() { vector::iterator it; while (int(m_vecLoginInfo.size()) > 0) { it = m_vecLoginInfo.begin(); delete (*it); m_vecLoginInfo.erase(it); } m_vecLoginInfo.clear(); } BOOL CDlgLogin::OnInitDialog() { CDialog::OnInitDialog(); CString strID=_T(""), strPW=_T(""); int nIDCnt = AfxGetApp()->GetProfileInt(_T("Login"), _T("Count"), 0); if (nIDCnt == 0) { strID.Format(_T("ID_%02d"), nIDCnt); strPW.Format(_T("PW_%02d"), nIDCnt); AfxGetApp()->WriteProfileInt(_T("Login"), _T("Count"), 1); AfxGetApp()->WriteProfileString(_T("Login"), strID, _T("dit")); AfxGetApp()->WriteProfileString(_T("Login"), strPW, _T("dit")); } // read login info to registry GetLoginInfo(); // make login log file MakeLogFile(); if (m_nLoginLevel == 0) { } return TRUE; } BOOL CDlgLogin::GetLoginInfo() { ClearLoginInfo(); CString strID=_T(""), strPW=_T(""), strLV=_T(""); int nIDCnt = AfxGetApp()->GetProfileInt(_T("Login"), _T("Count"), 0); for (int nID=0; nIDstrID = AfxGetApp()->GetProfileString(_T("Login"), strID); pLoginInfo->strPW = AfxGetApp()->GetProfileString(_T("Login"), strPW); pLoginInfo->nLevel = AfxGetApp()->GetProfileInt(_T("Login"), strLV, 0); m_vecLoginInfo.push_back(pLoginInfo); } return TRUE; } void CDlgLogin::OnOK() { // TODO: Add extra validation here UpdateData(TRUE); if (m_strEditID == _T("")) { AfxMessageBox(_T("·Î±×ÀÎ ½ÇÆÐ! IDÀ» ÀûÀ¸¼¼¿ä."), MB_OK | MB_ICONERROR); return; } GetLoginInfo(); if (int(m_vecLoginInfo.size()) <= 0) { AfxMessageBox(_T("·Î±×ÀÎ ½ÇÆÐ! µî·ÏµÈ ID°¡ ¾ø½À´Ï´Ù."), MB_OK | MB_ICONERROR); return; } vector::iterator it; for (it=m_vecLoginInfo.begin(); it!=m_vecLoginInfo.end(); it++) { if ((*it)->strID == m_strEditID) { if ((*it)->strPW == m_strEditPassword) { if (it == m_vecLoginInfo.begin()) { m_nLoginLevel = 2; } else { m_nLoginLevel = 1; } AddLogString(_T("Login. ID[%s]"), (*it)->strID); break; } } } CDialog::OnOK(); } void CDlgLogin::OnCancel() { // TODO: Add extra cleanup here m_nLoginLevel = 0; CDialog::OnCancel(); } void CDlgLogin::OnButtonChange() { // TODO: Add your control notification handler code here UpdateData(TRUE); if (m_strEditID == _T("")) { AfxMessageBox(_T("º¯°æ ½ÇÆÐ! IDÀ» ÀûÀ¸¼¼¿ä."), MB_OK | MB_ICONERROR); return; } if (int(m_vecLoginInfo.size()) <= 0) { AfxMessageBox(_T("º¯°æ ½ÇÆÐ! µî·ÏµÈ ID°¡ ¾ø½À´Ï´Ù."), MB_OK | MB_ICONERROR); return; } if (m_strEditNewPwd1 != m_strEditNewPwd2) { AfxMessageBox(_T("º¯°æ ½ÇÆÐ! µÎ °³ÀÇ ºñ¹Ð¹øÈ£°¡ ÀÏÄ¡ÇÏÁö ¾Ê½À´Ï´Ù."), MB_OK | MB_ICONERROR); return; } BOOL bChange = FALSE; int nChangeIdx = -1; vector::iterator it; for (it=m_vecLoginInfo.begin(); it!=m_vecLoginInfo.end(); it++) { if ((*it)->strID == m_strEditID) { if (m_strEditPassword != (*it)->strPW) { AfxMessageBox(_T("º¯°æ ½ÇÆÐ! ±âÁ¸ ºñ¹Ð¹øÈ£°¡ ¿Ã¹Ù¸£Áö ¾Ê½À´Ï´Ù."), MB_OK | MB_ICONERROR); return; } (*it)->strPW.Format(_T("%s"), m_strEditNewPwd1); CString strMessage = _T(""); strMessage.Format(_T("º¯°æ ¿Ï·á! ID[%s], PW[%s]"), (*it)->strID, (*it)->strPW); AfxMessageBox(strMessage, MB_OK | MB_ICONINFORMATION); CString strTemp = _T(""); strTemp.Format(_T("%s"), (*it)->strPW); AddLogString(_T("Change Password. ID[%s], NewPW[%s*]"), (*it)->strID, strTemp.GetBufferSetLength(strTemp.GetLength()-1)); bChange = TRUE; } nChangeIdx++; } if (bChange) { CString strPW=_T(""); strPW.Format(_T("PW_%02d"), nChangeIdx); AfxGetApp()->WriteProfileString(_T("Login"), strPW, m_strEditNewPwd1); AfxMessageBox(_T("ºñ¹Ð¹øÈ£°¡ º¯°æµÇ¾ú½À´Ï´Ù.\n\n´Ù½Ã ·Î±×ÀÎ ÇØ ÁÖ¼¼¿ä."), MB_OK | MB_ICONINFORMATION); } else { AfxMessageBox(_T("º¯°æ ½ÇÆÐ! ÀÏÄ¡ÇÏ´Â ID°¡ ¾ø½À´Ï´Ù."), MB_OK | MB_ICONERROR); } } void CDlgLogin::OnBnClickedButtonCreateId() { if (m_nLoginLevel != 2) { AfxMessageBox(_T("»ý¼º ±ÇÇÑÀÌ ¾ø½À´Ï´Ù."), MB_OK | MB_ICONERROR); return; } // TODO: ¿©±â¿¡ ÄÁÆ®·Ñ ¾Ë¸² 󸮱â Äڵ带 Ãß°¡ÇÕ´Ï´Ù. UpdateData(TRUE); if(m_strEditCreateID == _T("")) { AfxMessageBox(_T("ID¸¦ ³Ö¾îÁÖ¼¼¿ä."), MB_OK | MB_ICONERROR); return; } if(m_strEditCreatePW == _T("")) { AfxMessageBox(_T("Password¸¦ ³Ö¾îÁÖ¼¼¿ä."), MB_OK | MB_ICONERROR); return; } if(m_strEditCreatePW == _T("")) { AfxMessageBox(_T("Check Password¸¦ ³Ö¾îÁÖ¼¼¿ä."), MB_OK | MB_ICONERROR); return; } if(m_strEditCreatePW.GetLength() <= 5) { AfxMessageBox(_T("Password´Â 6ÀÚ ÀÌ»óÀ¸·Î ³Ö¾îÁÖ¼¼¿ä."), MB_OK | MB_ICONERROR); return; } if (int(m_vecLoginInfo.size()) > 0) { vector::iterator it; for (it=m_vecLoginInfo.begin(); it!=m_vecLoginInfo.end(); it++) { if ((*it)->strID == m_strEditCreateID) { AfxMessageBox(_T("»ý¼º ½ÇÆÐ! µ¿ÀÏ ID°¡ ÀÖ½À´Ï´Ù."), MB_OK | MB_ICONERROR); return; } } } if (m_strEditCreatePW == m_strEditCreateCheckPW) { CDataLoginInfo* pLoginInfo = new CDataLoginInfo; pLoginInfo->strID.Format(_T("%s"), m_strEditCreateID); pLoginInfo->strPW.Format(_T("%s"), m_strEditCreatePW); pLoginInfo->nLevel = 1; m_vecLoginInfo.push_back(pLoginInfo); CString strID=_T(""), strPW=_T(""), strLV=_T(""); strID.Format(_T("ID_%02d"), int(m_vecLoginInfo.size())-1); strPW.Format(_T("PW_%02d"), int(m_vecLoginInfo.size())-1); strLV.Format(_T("LV_%02d"), int(m_vecLoginInfo.size())-1); AfxGetApp()->WriteProfileInt(_T("Login"), _T("Count"), int(m_vecLoginInfo.size())); AfxGetApp()->WriteProfileString(_T("Login"), strID, pLoginInfo->strID); AfxGetApp()->WriteProfileString(_T("Login"), strPW, pLoginInfo->strPW); AfxGetApp()->WriteProfileInt(_T("Login"), strLV, pLoginInfo->nLevel); CString strMessage = _T(""); strMessage.Format(_T("»ý¼º ¼º°ø! ID[%s], PW[%s], LV[%d]"), pLoginInfo->strID, pLoginInfo->strPW, pLoginInfo->nLevel); AfxMessageBox(strMessage, MB_OK | MB_ICONINFORMATION); CString strTemp = _T(""); strTemp.Format(_T("%s"), pLoginInfo->strPW); AddLogString(_T("Create Account. ID[%s], PW[%s*], LV[%d]"), pLoginInfo->strID, strTemp.GetBufferSetLength(strTemp.GetLength()-1), pLoginInfo->nLevel); } else { AfxMessageBox(_T("»ý¼º ½ÇÆÐ! µÎ °³ÀÇ ºñ¹Ð¹øÈ£°¡ ÀÏÄ¡ÇÏÁö ¾Ê½À´Ï´Ù."), MB_OK | MB_ICONERROR); return; } } void CDlgLogin::OnBnClickedButtonFindPassword() { // TODO: ¿©±â¿¡ ÄÁÆ®·Ñ ¾Ë¸² 󸮱â Äڵ带 Ãß°¡ÇÕ´Ï´Ù. UpdateData(TRUE); if (int(m_vecLoginInfo.size()) <= 0) { AfxMessageBox(_T("ã±â ½ÇÆÐ! µî·ÏµÈ ID°¡ ¾ø½À´Ï´Ù."), MB_OK | MB_ICONERROR); return; } if (m_strEditID == _T("")) { AfxMessageBox(_T("ã±â ½ÇÆÐ! IDÀ» ÀûÀ¸¼¼¿ä."), MB_OK | MB_ICONERROR); return; } vector::iterator it; for (it=m_vecLoginInfo.begin(); it!=m_vecLoginInfo.end(); it++) { if ((*it)->strID == m_strEditID) { CString strPassword = _T(""); CString strTemp = _T(""); strTemp.Format(_T("%s"), (*it)->strPW); if ((*it)->strPW.GetLength() <= 1) strPassword.Format(_T("%s"), strTemp); else strPassword.Format(_T("%s*"), strTemp.GetBufferSetLength(strTemp.GetLength()-1)); AfxMessageBox(strPassword, MB_OK | MB_ICONINFORMATION); return; } } AfxMessageBox(_T("ã±â ½ÇÆÐ! µ¿ÀÏ ID°¡ ¾ø½À´Ï´Ù."), MB_OK | MB_ICONERROR); } BOOL CDlgLogin::MakeLogFile() { CreateDirectory(_REVIEW_RECIPE_LOGIN_LOG_PATH_, NULL); m_TimeLogFile = CTime::GetCurrentTime(); m_strLoginLogName.Format(_T("%s\\Login_%02d%02d%02d.log"), _REVIEW_RECIPE_LOGIN_LOG_PATH_, m_TimeLogFile.GetYear(), m_TimeLogFile.GetMonth(), m_TimeLogFile.GetDay()); if (m_pFileLog) delete m_pFileLog; m_pFileLog = new CFile(); if (m_pFileLog->Open(m_strLoginLogName, CFile::modeCreate|CFile::modeNoTruncate|CFile::modeWrite|CFile::shareDenyNone)) m_pFileLog->Close(); else return FALSE; return TRUE; } BOOL CDlgLogin::AddLogString(const CString& strData) { if(m_pFileLog == NULL) return FALSE; SYSTEMTIME sysTime; GetLocalTime(&sysTime); CString strTimeStamp; // ³¯Â¥°¡ ¹Ù²î¸é ÆÄÀϸíÀ» °»½ÅÇØ¼­ ¾´´Ù. if ((sysTime.wYear != m_TimeLogFile.GetYear()) || (sysTime.wMonth != m_TimeLogFile.GetMonth()) || (sysTime.wDay != m_TimeLogFile.GetDay()) || !m_pFileLog) MakeLogFile(); if (m_pFileLog->Open(m_strLoginLogName, CFile::modeNoTruncate | CFile::modeWrite | CFile::shareDenyNone )) { // À¯´ÏÄÚµå ÆÄÀÏÀÇ ½ÃÀÛÀº BOM(0xFEFF) À̾î¾ß ÇÑ´Ù. TCHAR strCommand = 0xFEFF; CString strLog; strTimeStamp.Format(_T("[%02d:%02d:%02d.%03d]"), sysTime.wHour, sysTime.wMinute, sysTime.wSecond, sysTime.wMilliseconds); #ifdef UNICODE strLog.Format(_T("%c%s %s\r\n"), strCommand, strTimeStamp, strData); #else strLog.Format(_T("%s %s\r\n"), strTimeStamp, strData); #endif m_pFileLog->SeekToEnd(); m_pFileLog->Write(strLog.GetBuffer(0), strLog.GetLength() * sizeof(TCHAR)); strLog.ReleaseBuffer(); m_pFileLog->Close(); } return TRUE; } BOOL CDlgLogin::AddLogString(const TCHAR* strData, ...) { va_list list; TCHAR strText[2000] = {0}; va_start(list, strData); _vstprintf_s(strText, strData, list); va_end(list); CString strTransData = _T(""); strTransData = strText; AddLogString(strTransData); return TRUE; }