// PasswordGeneratorDlg.cpp : ±¸Çö ÆÄÀÏ // #include "stdafx.h" #include "PasswordGenerator.h" #include "PasswordGeneratorDlg.h" #include ".\passwordgeneratordlg.h" #ifdef _DEBUG #define new DEBUG_NEW #endif extern "C" { #include "MD5/global.h" #include "MD5/md5.h" } #include "Math/Random.h" // ÀÀ¿ë ÇÁ·Î±×·¥ Á¤º¸¿¡ »ç¿ëµÇ´Â CAboutDlg ´ëÈ­ »óÀÚÀÔ´Ï´Ù. class CAboutDlg : public CDialog { public: CAboutDlg(); // ´ëÈ­ »óÀÚ µ¥ÀÌÅÍ enum { IDD = IDD_ABOUTBOX }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV Áö¿ø // ±¸Çö protected: DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) END_MESSAGE_MAP() // CPasswordGeneratorDlg ´ëÈ­ »óÀÚ CPasswordGeneratorDlg::CPasswordGeneratorDlg(CWnd* pParent /*=NULL*/) : CDialog(CPasswordGeneratorDlg::IDD, pParent) { m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CPasswordGeneratorDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Control(pDX, IDC_EDIT2, m_Output); DDX_Control(pDX, IDC_EDIT1, m_PasswordSize); DDX_Control(pDX, IDC_CHECK1, m_SpecialChar); DDX_Control(pDX, IDC_EDIT3, m_InputCode); } BEGIN_MESSAGE_MAP(CPasswordGeneratorDlg, CDialog) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() //}}AFX_MSG_MAP ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedButton1) ON_BN_CLICKED(IDC_BUTTON2, OnBnClickedButton2) END_MESSAGE_MAP() // CPasswordGeneratorDlg ¸Þ½ÃÁö 󸮱â BOOL CPasswordGeneratorDlg::OnInitDialog() { CDialog::OnInitDialog(); // ½Ã½ºÅÛ ¸Þ´º¿¡ "Á¤º¸..." ¸Þ´º Ç׸ñÀ» Ãß°¡ÇÕ´Ï´Ù. // IDM_ABOUTBOX´Â ½Ã½ºÅÛ ¸í·É ¹üÀ§¿¡ ÀÖ¾î¾ß ÇÕ´Ï´Ù. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // ÀÌ ´ëÈ­ »óÀÚÀÇ ¾ÆÀÌÄÜÀ» ¼³Á¤ÇÕ´Ï´Ù. ÀÀ¿ë ÇÁ·Î±×·¥ÀÇ ÁÖ Ã¢ÀÌ ´ëÈ­ »óÀÚ°¡ ¾Æ´Ò °æ¿ì¿¡´Â // ÇÁ·¹ÀÓ¿öÅ©°¡ ÀÌ ÀÛ¾÷À» ÀÚµ¿À¸·Î ¼öÇàÇÕ´Ï´Ù. SetIcon(m_hIcon, TRUE); // Å« ¾ÆÀÌÄÜÀ» ¼³Á¤ÇÕ´Ï´Ù. SetIcon(m_hIcon, FALSE); // ÀÛÀº ¾ÆÀÌÄÜÀ» ¼³Á¤ÇÕ´Ï´Ù. // TODO: ¿©±â¿¡ Ãß°¡ ÃʱâÈ­ ÀÛ¾÷À» Ãß°¡ÇÕ´Ï´Ù. return TRUE; // ÄÁÆ®·Ñ¿¡ ´ëÇÑ Æ÷Ä¿½º¸¦ ¼³Á¤ÇÏÁö ¾ÊÀ» °æ¿ì TRUE¸¦ ¹ÝȯÇÕ´Ï´Ù. } void CPasswordGeneratorDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID, lParam); } } // ´ëÈ­ »óÀÚ¿¡ ÃÖ¼ÒÈ­ ´ÜÃ߸¦ Ãß°¡ÇÒ °æ¿ì ¾ÆÀÌÄÜÀ» ±×¸®·Á¸é // ¾Æ·¡ Äڵ尡 ÇÊ¿äÇÕ´Ï´Ù. ¹®¼­/ºä ¸ðµ¨À» »ç¿ëÇÏ´Â MFC ÀÀ¿ë ÇÁ·Î±×·¥ÀÇ °æ¿ì¿¡´Â // ÇÁ·¹ÀÓ¿öÅ©¿¡¼­ ÀÌ ÀÛ¾÷À» ÀÚµ¿À¸·Î ¼öÇàÇÕ´Ï´Ù. void CPasswordGeneratorDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // ±×¸®±â¸¦ À§ÇÑ µð¹ÙÀ̽º ÄÁÅØ½ºÆ® SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); // Ŭ¶óÀÌ¾ðÆ® »ç°¢Çü¿¡¼­ ¾ÆÀÌÄÜÀ» °¡¿îµ¥¿¡ ¸ÂÃä´Ï´Ù. int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // ¾ÆÀÌÄÜÀ» ±×¸³´Ï´Ù. dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } } // »ç¿ëÀÚ°¡ ÃÖ¼ÒÈ­µÈ âÀ» ²ô´Â µ¿¾È¿¡ Ä¿¼­°¡ Ç¥½ÃµÇµµ·Ï ½Ã½ºÅÛ¿¡¼­ // ÀÌ ÇÔ¼ö¸¦ È£ÃâÇÕ´Ï´Ù. HCURSOR CPasswordGeneratorDlg::OnQueryDragIcon() { return static_cast(m_hIcon); } void CPasswordGeneratorDlg::OnBnClickedButton1() { // TODO: ¿©±â¿¡ ÄÁÆ®·Ñ ¾Ë¸² 󸮱â Äڵ带 Ãß°¡ÇÕ´Ï´Ù. char strTemp[512]; int iSize = 0; m_PasswordSize.GetWindowText(strTemp, 512); iSize = atoi(strTemp); if(iSize < 4 || iSize > 32) { AfxMessageBox("4ÀÚ ÀÌ»ó 32ÀÚ ÀÌÇÏ ¿©¾ßÇÕ´Ï´Ù.", MB_OK); return; } char szPassword[512]; char szPasswordMD5[512]; char szKeyTable[512]; ZeroMemory(szKeyTable, sizeof(szKeyTable)); strcpy(szKeyTable, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"); if(m_SpecialChar.GetCheck()) { strcat(szKeyTable, "~!@#$%^&()-=_+[]{}"); } int iKeyTable = strlen(szKeyTable); Math::RandomInt random(GetTickCount()); for(int i = 0; i < iSize; ++i) { int key = random.Next(iKeyTable); szPassword[i] = szKeyTable[key]; } szPassword[iSize] = 0; MD5_CTX context; unsigned char digest[16] ; memset( digest, 0, sizeof( char ) * 16 ) ; MD5Init(&context); MD5Update(&context, reinterpret_cast( szPassword ), strlen( szPassword ) ); MD5Final(digest, &context); ZeroMemory(szPasswordMD5, sizeof(szPasswordMD5)); for (int i = 0; i < 16; ++i) { sprintf (szPasswordMD5 + i * 2, "%02x", digest[i]); } char szOut[2048]; sprintf(szOut, "Password : %s\r\n\r\nMD5 : %s", szPassword, szPasswordMD5); m_Output.SetWindowText(szOut); return; } void CPasswordGeneratorDlg::OnBnClickedButton2() { // TODO: ¿©±â¿¡ ÄÁÆ®·Ñ ¾Ë¸² 󸮱â Äڵ带 Ãß°¡ÇÕ´Ï´Ù. char szPassword[512]; char szPasswordMD5[512]; int iSize = 0; m_InputCode.GetWindowText(szPassword, 512); iSize = strlen(szPassword); if(iSize < 4 || iSize > 32) { AfxMessageBox("4ÀÚ ÀÌ»ó 32ÀÚ ÀÌÇÏ ¿©¾ßÇÕ´Ï´Ù.", MB_OK); return; } MD5_CTX context; unsigned char digest[16] ; memset( digest, 0, sizeof( char ) * 16 ) ; MD5Init(&context); MD5Update(&context, reinterpret_cast( szPassword ), strlen( szPassword ) ); MD5Final(digest, &context); ZeroMemory(szPasswordMD5, sizeof(szPasswordMD5)); for (int i = 0; i < 16; ++i) { sprintf (szPasswordMD5 + i * 2, "%02x", digest[i]); } char szOut[2048]; sprintf(szOut, "Password : %s\r\n\r\nMD5 : %s", szPassword, szPasswordMD5); m_Output.SetWindowText(szOut); }