Move git root from Client/ to src/ to track all source code: - Client: Game client source (moved to Client/Client/) - Server: Game server source - GameTools: Development tools - CryptoSource: Encryption utilities - database: Database scripts - Script: Game scripts - rylCoder_16.02.2008_src: Legacy coder tools - GMFont, Game: Additional resources 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
261 lines
5.7 KiB
C++
261 lines
5.7 KiB
C++
// 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<WPARAM>(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<HCURSOR>(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<unsigned char *>( 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<unsigned char *>( 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);
|
|
}
|