-
Notifications
You must be signed in to change notification settings - Fork 0
/
Password System.h
185 lines (144 loc) · 5.61 KB
/
Password System.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#pragma once
#ifndef UNICODE
#define UNICODE
#endif // !UNICODE
#include <Windows.h>
#include <stdlib.h>
LRESULT CALLBACK PasswordProc(HWND, UINT, WPARAM, LPARAM);
bool check_value = true;
bool reset_value = false;
HWND passwordWindow, Continue, reset;
void Body(HWND);
void DestroyWindows(HWND window1, HWND window2)
{
DestroyWindow(window1);
DestroyWindow(window2);
}
void PasswordSystem(HINSTANCE instance)
{
WNDCLASS wc = {};
wc.hbrBackground = CreateSolidBrush(RGB(0, 0, 39));
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hInstance = instance;
wc.lpfnWndProc = PasswordProc;
wc.lpszClassName = L"name";
RegisterClass(&wc);
passwordWindow = CreateWindowEx(0, L"name", L"Password", WS_MINIMIZEBOX | WS_SYSMENU | WS_VISIBLE, 500, 300, 400, 240, NULL, NULL, instance, NULL);
MSG msg = {};
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
HFONT Signfont = CreateFont(40, 20, 0, 0, FW_EXTRABOLD, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS,
ANTIALIASED_QUALITY, DEFAULT_PITCH, TEXT("CALIBRI"));
HFONT signSector = CreateFont(30, 0, 0, 0, FW_EXTRABOLD, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS,
ANTIALIASED_QUALITY, DEFAULT_PITCH, TEXT("CALIBRI"));
HFONT editFont = CreateFont(30, 0, 0, 0, FW_EXTRABOLD, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS,
ANTIALIASED_QUALITY, DEFAULT_PITCH, TEXT("CALIBRI"));
HWND edit;
constexpr auto OnClick_Continue = 1;
constexpr auto OnClick_Reset = 2;
LRESULT CALLBACK PasswordProc(HWND hwnd, UINT mas, WPARAM wp, LPARAM lp)
{
switch (mas)
{
case WM_CREATE:
Body(hwnd);
break;
case WM_CTLCOLORSTATIC:
SetBkMode((HDC)wp, TRANSPARENT);
SetTextColor((HDC)wp, RGB(255, 255, 255));
return GetClassLongPtr(hwnd, GCL_HBRBACKGROUND);
break;
case WM_DRAWITEM:
{
LPDRAWITEMSTRUCT lpds = (DRAWITEMSTRUCT*)lp;
if (lpds->hwndItem == Continue)
{
SIZE size;
GetTextExtentPoint32A(lpds->hDC, "CONTINUE", strlen("CONTINUE"), &size);
SetTextColor(lpds->hDC, RGB(255, 255, 255));
SetBkColor(lpds->hDC, RGB(0, 0, 160));
ExtTextOutA(lpds->hDC, (lpds->rcItem.left + 3), (lpds->rcItem.top + 9), ETO_OPAQUE, &lpds->rcItem,
"CONTINUE", strlen("CONTINUE"), NULL);
}
if (lpds->hwndItem == reset)
{
SIZE size;
GetTextExtentPoint32A(lpds->hDC, "RESET", strlen("RESET"), &size);
SetTextColor(lpds->hDC, RGB(255, 255, 255));
SetBkColor(lpds->hDC, RGB(0, 0, 160));
ExtTextOutA(lpds->hDC, (lpds->rcItem.left + 19), (lpds->rcItem.top + 10), ETO_OPAQUE, &lpds->rcItem,
"RESET", strlen("RESET"), NULL);
}
DrawEdge(lpds->hDC, &lpds->rcItem, (lpds->itemState & ODS_SELECTED ? EDGE_BUMP : EDGE_SUNKEN), BF_SOFT);
return TRUE;
}
break;
case WM_COMMAND:
switch (wp)
{
case OnClick_Continue:
{
//const int _size = sizeof(edit);
char PasswordItself[] = "Hello";
char PasswordValue[100];
GetWindowTextA(edit, PasswordValue, 100);
if (strcmp(PasswordValue, PasswordItself) == 0)
{
DestroyWindows(passwordWindow,NULL);
check_value = false;
}
else {
MessageBox(NULL, L"Wrong Password", L"Incorrect Password", MB_OK);
}
}
break;
case OnClick_Reset:
{
if (MessageBox(NULL, L"Dear user, please be informed that by clicking on the reset button the password window will be closed and the reset window will be opened.\n\nAlso note that after you have changed your password the window will be closed automatically, that proves your password was changed successfully.\n\nYou can click on Cancel to cancel this and use the existing password.\nIf you click OK there's no going back.",
L"Info", MB_OKCANCEL | MB_ICONINFORMATION) == IDOK)
{
reset_value = true;
DestroyWindow(passwordWindow);
}
}
break;
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, mas, wp, lp);
break;
}
return 0;
}
void Body(HWND hwnd)
{
//Sign saying Password
HWND Sign = CreateWindowEx(0, L"STATIC", L"INPUT PASSWORD", WS_CHILD | WS_VISIBLE, 55, 0, 300, 50, hwnd, NULL, NULL, NULL);
SendMessage(Sign, WM_SETFONT, (WPARAM)Signfont, MAKELPARAM(TRUE, 0));
//Border around password sector
CreateWindowEx(0, L"STATIC", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | SS_SUNKEN, 5, 70, 375, 50, hwnd, NULL, NULL, NULL);
//Sign to show this is where you enter password
HWND pword = CreateWindowEx(0, L"STATIC", L"Password:", WS_CHILD | WS_VISIBLE, 15, 80, 110, 30, hwnd, NULL, NULL, NULL);
SendMessage(pword, WM_SETFONT, (WPARAM)signSector, MAKELPARAM(TRUE, 0));
//Space for user to type password
edit = CreateWindowEx(0, L"EDIT", NULL, WS_CHILD | WS_VISIBLE | ES_PASSWORD | ES_AUTOHSCROLL, 138, 80, 230, 30, hwnd, NULL, NULL, NULL);
SendMessage(edit, WM_SETFONT, (WPARAM)editFont, MAKELPARAM(TRUE, 0));
/*
* From this point you get the buttons that are used in the password system
*/
//Button for Reset
reset = CreateWindowEx(0, L"BUTTON", L"RESET", WS_CHILD | WS_VISIBLE | BS_FLAT | BS_OWNERDRAW, 0, 152, 110, 50,
hwnd, (HMENU)OnClick_Reset, (HINSTANCE)GetWindowLong(hwnd, GWLP_HINSTANCE), NULL);
SendMessage(reset, WM_SETFONT, (WPARAM)editFont, MAKELPARAM(TRUE, 0));
//Button for Continue
Continue = CreateWindowEx(0, L"BUTTON", L"CONTINUE", WS_CHILD | WS_VISIBLE | BS_FLAT | BS_OWNERDRAW, 269, 152, 115, 50,
hwnd, (HMENU)OnClick_Continue, (HINSTANCE)GetWindowLong(hwnd,GWLP_HINSTANCE), NULL);
SendMessage(Continue, WM_SETFONT, (WPARAM)editFont, MAKELPARAM(TRUE, 0));
}