Password

Pages: 12
If you can and if it's not asking too much, can you make it so it shows "Welcome" or just a "*" while you put information in.
yeah no problem dude... I had so business to attend to yesterday so I'll get working on the code today and should be posted today
Last edited on
I couldn't Include a lot more stuff because my compiler was being suckish and has a intellisense bug(something that you get from microsoft compilers) so A ton of my code had to be removed, including the encryption portion unfortunately... I was able to salvage some of it though. My coding technique and clarity are kinda bad here... But I had to do it quick, while working around my buggy compiler.

Anyways, Full Source Code... Not sure if it will work with your compiler though, there are some specialties.

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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#include <iostream>
#include <fstream>                // File Stream... I believe your familiar
#include <string>
#include <Windows.h>              // This enables special features such as Sleep... Very useful but constrains your api to windows only of course.
#include <time.h>
#include "conio.h"                // This allows getch/ get character to be used. getch can be used to get a character or generically make a pause/continue.
#pragma comment(lib, "winmm.lib") // This enables the music

using namespace std;


int staticLoad() // Exterior function
{
	cout << "Loading";
	Sleep(100); // A more simple delay that works by milliseconds. It goes along with the Windows header
	cout << ".";
	Sleep(100);
	cout << ".";
	Sleep(100);
	cout << ".";
	Sleep(800);
    system("cls");
	cout << "Loading";
	Sleep(100);
	cout << ".";
	Sleep(100);
	cout << ".";
	Sleep(100);
	cout << "." << flush; // Flush just clears the input buffer. Its not needed but is a good thing to use every now and then.
   system("cls");
	return 0;
}

int main() // Main function
{
	system("title SYSTEM LOG-IN");
	//PlaySound(TEXT("FILENAME.wav"), NULL, SND_ASYNC | SND_LOOP); Music playing statement. Music file must be in . WAV format and be in the directory.
	//PlaySound(NULL, NULL, NULL); This stops the music.

    SetForegroundWindow(GetConsoleWindow()); // All these 5 lines are used to make the window fullscreen. In my experience it always runs with XP,
	 keybd_event(VK_MENU, MapVirtualKey(VK_MENU, 0), 0, 0); //not windows 7 for some reason... Not sure if it will work because of my limitations of OS.
    keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), 0, 0); 
    keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), KEYEVENTF_KEYUP, 0); 
    keybd_event(VK_MENU, MapVirtualKey(VK_MENU, 0), KEYEVENTF_KEYUP, 0);                                                        
   

	staticLoad(); // Load the exterior function above that makes a fake loading timer
	Sleep(500);
	int ntTries=0; // Tries timer that will increase every failed password, and at 5 wrong information inputs it will shutdown the computer though an
				   // If evaluation
	string szUACt_1 = "Drue"; // sz means string so you can identify it later on; User-Account-Control Title: 1(Account Username 1)
	string szUACp_1 = "Blake"; // User-Account-Control Password: 1(Account Password 1)
RETRY: // This used when the user had incorrect input, and gets another chance to try again by returning to the question and evaluation.
	system("color a"); // Simple system color [green]
	time_t rawtime;    // time stamp stuff so that the time the program is executed is logged in an external text file.
	time ( &rawtime );

	string szTime = ctime (&rawtime); // Set the timestamp equal to a alpha variable.
	string szUsername; // sz doesn't change anything, its just a coding technique to let you know wherever its used that it is a string/ sz.
	string szPassword;
	string szPasswordChar;
	string szCharacterDisp; // What the final output of ****** characters will be when user enters password
	string szGetChar_1, szGetChar_2, szGetChar_3, szGetChar_4, szGetChar_5, szGetChar_6, szGetChar_7, szGetChar_8, szGetChar_9;
	BOOL vkReturn_1, vkReturn_2, vkReturn_3, vkReturn_4, vkReturn_5, vkReturn_6, vkReturn_7, vkReturn_8; // Regular variables, based on the purpose of the ENTER key for an if statement.
	
	
	
	cout << "USERNAME: ";
	cout << " ";
	cin >> szUsername;
	cout << "PASSWORD: ";
	szGetChar_1 = _getch(); // getch makes it where you can invisibly input a character and save it to a variable.[get character]
	vkReturn_1 = GetKeyState(VK_RETURN); // This determines if enter was pressed.
	if (vkReturn_1){ // If enter was pressed(meaning password is done) then do the following... skip the password input and evaluate input data.
		goto NEXT;
	}
	szPassword += "*";
	szGetChar_2 = _getch();
	vkReturn_2 = GetKeyState(VK_RETURN);
	if (vkReturn_2){
		goto NEXT;
	}
	szPassword += "*";
	szGetChar_3 = _getch();
	vkReturn_3 = GetKeyState(VK_RETURN);
	if (vkReturn_3){
		goto NEXT;
	}
	szPassword += "*";
	szGetChar_4 = _getch();
	vkReturn_4 = GetKeyState(VK_RETURN);
	if (vkReturn_4){
		goto NEXT;
	}
	szPassword += "*";
	szGetChar_5 = _getch();
	vkReturn_5 = GetKeyState(VK_RETURN);
	if (vkReturn_5){
		goto NEXT;
	}
	szPassword += "*";
	szGetChar_6 = _getch();
	vkReturn_6 = GetKeyState(VK_RETURN);
	if (vkReturn_6){
		goto NEXT;
	}
	szPassword += "*";
	szGetChar_7 = _getch();
	vkReturn_7 = GetKeyState(VK_RETURN);
	if (vkReturn_7){
		goto NEXT;
	}
	szPassword += "*";
	szGetChar_8 = _getch();
	vkReturn_8 = GetKeyState(VK_RETURN);
	if (vkReturn_8){
		goto NEXT;
	}
	szPassword += "*";
	szGetChar_9 = _getch(); // Only goes up to nine... Dont use a password that is more than 9 characters.

NEXT:
	/*Output the password*/
	cout << " ";
	cout << szPassword;
	cout << endl;
	staticLoad();
	system("cls");
	/*Log Access request*/
	ofstream Log;
    Log.open("C:/Users/Matt/Documents/log-in events/Log.txt", ios::app);
    Log << "[ACCESS ENTRY]\n\nDATE: " << szTime << "\nUSERNAME: " << szUsername << "\nPASSWORD: " << szCharacterDisp << "\n\n";
	/*Compare User Input to database*/
	if (szUsername == szUACt_1){ // If what they entered equal the username the console knows of, then continue...
		if (szPassword == szUACp_1){
			// ALLOW ACCESS TO USER
			goto VERIFIED;
		}	
	}

	else {						// If not then do this.
		ntTries += 1;
		system("cls");
		if (ntTries == 1){
		cout << "The Username/ Password is incorrect.";
		Sleep(1500);
		system("cls");
		goto RETRY;
		}
		if (ntTries == 2){
		cout << "The Username/ Password is incorrect.";
		Sleep(1500);
		system("cls");
		goto RETRY;
		}
		if (ntTries ==  3){
        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 14);
		cout << "The Username/ Password is incorrect.";
		Sleep(1500);
		system("cls");
		Sleep(125);
		cout << "The Username/ Password is incorrect.";
		system("cls");
		Sleep(125);
		cout << "The Username/ Password is incorrect.";
		Sleep(2500);
		system("cls");
		goto RETRY;
		}
		if (ntTries ==  4){
        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 14);
		cout << "The Username/ Password is incorrect.";
		Sleep(1500);
		system("cls");
		Sleep(125);
		cout << "The Username/ Password is incorrect.";
		system("cls");
		Sleep(125);
		cout << "The Username/ Password is incorrect.";
		Sleep(2500);
		system("cls");
		goto RETRY;
		}
		if (ntTries == 5){
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
		cout << "The Username/ Password is incorrect.";
		Sleep(2500);
		system("cls");
		Sleep(125);
		cout << "The Username/ Password is incorrect.";
		system("cls");
		Sleep(125);
		cout << "The Username/ Password is incorrect.";
		system("cls");
		Sleep(125);
		cout << "The Username/ Password is incorrect.";
		Sleep(2500);
		system("cls");
		Sleep(2500);
		cout << "ACCESS DENIED." << endl;
		Sleep(1000);
		}
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 240);
		cout << "This machine will now shutdown";
		Sleep(2000);
		cout << ".";
		Sleep(2000);
		cout << ".";
		Sleep(2000);
		cout << ".";
		system("shutdown /f /s /t 6"); // The program will shutdown the computer and print a message to the screen. 6 seconds is better so no damage is done by user.
		return 0;
		// EXIT PROGRAM AND COMPUTER.
	}

VERIFIED:
	cout << "Welcome. Access Granted." << endl; // Allows access without interruption.
	Sleep(2500);
	return 0;
}
Last edited on
Thanks. I have to edit just a little bit (like the Path) cause this is XP.
I had to take the first line out of the full screen command.
SetForegroundWindow(GetConsoleWindow()); // All these 5 lines are used to make the window fullscreen. In my experience it always runs with XP,

BTW it doesn't record the Password. It show's the username but not the password. Just asking, is there a way we could type in word like 'new' or 'reset', then it let us reset our passwords. And it would look for the file then compare passwords.

this is just part of the whole thing (in pseudo code)

Look for szUsername.txt. // Where username.txt would be C:\Password Log\[Username.txt] (Username would be the variable.0
If found
{ read then open,
Enter password
if password == whatever's in the Username.txt
Exit}


http://www.codeblocks.org/downloads/26

It's a download for the compiler I use. (If you want to use it.)
Last edited on
As some people have already, I just thought I'd warn you that this won't stop someone determined to get past it. ALT+F4 will most likely close it. On the other hand, there's no harm in having a play around :) Just so long as you know that it's far from fool proof...

Regards
-Xander314
Last edited on
Alt+F4 won't close it. As long as it is in fullscreen. I know that combination and I've tried it. You could open task manager, but other than that I'm pretty sure it's fine for what I need it for. I'm sure there's some code that makes it a priority and won't let you do anything else until you type in the password.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#pragma endregion
	private: System::Void btnPraySubmit_Click(System::Object^  sender, System::EventArgs^  e) {




   String^ fileName = "G:\\Flash drive\\C++ Programs\\GraceAG\\Pray.txt";

   StreamWriter^ sw = gcnew StreamWriter(fileName);
   sw->WriteLine("A text file is born!");
   sw->Write("You can use WriteLine");
   sw->WriteLine("...or just Write");
   sw->WriteLine("and do {0} output too.", "formatted");
   sw->WriteLine("You can also send non-text objects:");
   sw->WriteLine(DateTime::Now);
   sw->Close();
   Console::WriteLine("a new file ('{0}') has been written", fileName);

   return 0;

				 PrayRequest::Hide();
			 }


^^^^^^^^^^^ Thats an exert from my code for the more advanced program I'm making. I posted the link to download in a previous reply. Ifstream and Ostream don't work in Windows Applications so I found that code on Microsoft.com, but it wont' work. That's just for me to see if it worked which it didn't. TxtbPrayName is the name of the text box under 'Do you have the need' that asks for your name. I want it to save that to a file, but when I tried this out, even this wouldn't work. Help?
That's CLI/C++ (.NET and C++'s bastard child), not C++.

Ifstream and Ostream don't work in Windows Applications
Yes, they do. What doesn't work is sending output to stdout or getting input from stdin (although I believe it's possible to tell Windows to redirect stdout to a file).
Do you know how?
@DoTTGaMMa What a coincidence.. I found you on this site....Lol, funny cause i was looking up stuff on here because of Ms.Hunter's Project
I'm surprised Duoas hasn't burned you for this; Try to refrain from using system() commands-- for color, use things like SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), *color number here*); and all you have to do to use this, is #include <Windows.h>
Topic archived. No new replies allowed.
Pages: 12