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 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
|
#include<iostream>
#include<fstream>
#include<conio.h>
#include <stdio.h>
#include <string.h>
#include <windows.h>
#include <winable.h>
#include <cmath>
#include<string>
using namespace std;
void Auth(); //prompt to enter password
void Members(); //where you place your program, to be accessed after successful password
void Userchange(); //disabled
void Passchange(); //unused
void First(); //prompt to enter a password if there isn't one on record (i.e first time opening program)
void menu(); //currently unused
void Select(); //selection menu to access pass change or program etc.
void encrypt(string &e); //encrypt function
void decrypt (string &e); //decrypt function
string inpass;
string user;
string pass;
string first;
string firstconf;
int num = 0;
string com;
char c=' ';
main()
{
system("cls");
while(num==0)
{
system("cls");
ifstream Passfile("password.txt", ios::in);
Passfile>>inpass;
if (inpass == ""){
Passfile.close();
cout<<"It appears that this is your first time opening this program\nplease enter a password: ";
First();
}
else{
Auth();
}}}
void Auth()
{
ifstream Passfile("password.txt", ios::in);
Passfile>>inpass;
decrypt ( inpass );
system("cls");
cout<<"PASSWORD: ";
do //Loop until 'Enter' is pressed
{
c = getch();
switch(c)
{
case 0: //Catches f1-f12
{
getch();
break;
}
case 0xE0: //Catches arrow keys, end, home, page up/down, etc.
{
getch();
break;
}
case '\b':
{
if(pass.size() != 0) //If the password string contains data, erase last character
{
cout << "\b \b";
pass.erase(pass.size() - 1, 1);
}
break;
}
default:
{
if(isalnum(c) || ispunct(c))
{
pass += c;
cout << "*";
}
break;
}
};
}
while(c != '\r');
cout<<"\n";
Passfile.close();
if(pass==inpass)
{
Select();
}
else
{
cout<<"Wrong Password, please try again.";
Sleep(500);
main();
}
}
void First()
{
string first;
string firstconf;
do //Loop until 'Enter' is pressed
/*3 NUL
15 Shift Tab
16-25 Alt-Q/W/E/R/T/Y/U/I/O/P
30-38 Alt-A/S/D/F/G/H/I/J/K/L
44-50 Alt-Z/X/C/V/B/N/M
59-68 F1-F10 (disabled as softkeys)
71 Home
72 Up Arrow
73 PgUp
75 Left Arrow
77 Right Arrow
79 End
80 Down Arrow
81 PgDn
82 Ins
83 Del
84-93 F11-F20 (Shift-F1 to Shift-F10)
94-103 F21-F30 (Ctrl-F1 to Ctrl-F10)
104-113 F31-F40 (Alt-F1 to Alt-F10)
114 Ctrl-PrtScr
115 Ctrl-Left Arrow
116 Ctrl-Right Arrow
117 Ctrl-End
118 Ctrl-PgDn
119 Ctrl-Home
120-131 Alt-1/2/3/4/5/6/7/8/9/0/-/=
132 Ctrl-PgUp
133 F11
134 F12
135 Shift-F11
136 Shift-F12
137 Ctrl-F11
138 Ctrl-F12
139 Alt-F11
140 Alt-F12
*/
{
c = getch();
switch(c)
{
case 0: //Catches f1-f12
{
getch();
break;
}
case 0xE0: //Catches arrow keys, end, home, page up/down, etc.
{
getch();
break;
}
case '\b':
{
if(first.size() != 0) //If the password string contains data, erase last character
{
cout << "\b \b";
first.erase(first.size() - 1, 1);
}
break;
}
default:
{
if(isalnum(c) || ispunct(c))
{
first += c;
cout << "*";
}
break;
}
};
}
while(c != '\r');
cout<<"\n";
system("cls");
cout<<"Confirm Password: ";
do //Loop until 'Enter' is pressed
{
c = getch();
switch(c)
{
case 0: //Catches f1-f12
{
getch();
break;
}
case 0xE0: //Catches arrow keys, end, home, page up/down, etc.
{
getch();
break;
}
case '\b':
{
if(firstconf.size() != 0) //If the password string contains data, erase last character
{
cout << "\b \b";
firstconf.erase(firstconf.size() - 1, 1);
}
break;
}
default:
{
if(isalnum(c) || ispunct(c))
{
firstconf += c;
cout << "*";
}
break;
}
};
}
while(c != '\r');
cout<<"\n";
if (first.compare(firstconf) != 0){
cout<<"Passwords do not match, please try again";
Sleep(1000);
system("cls");
First();
}
else if(first.compare(firstconf) == 0) {
ofstream Passfile("password.txt", ios::out);
encrypt( first );
Passfile<<first;
Passfile.close();
cout<<"Password successfully registered! You may now access the program";
Sleep (1000);
system ("cls");
main();
}
}
void Members()
{
menu();
}
void menu(){
string str;
string x;
system ("cls");
cout <<"1. Write to a file\n";
cout<<"2. Read what you've written\n";
getline(cin, x);
if (x=="1"){
system("cls");
fstream myfile("example.txt", ios::out|ios::app);
myfile <<"\n";
getline (cin, str);
myfile << str;
myfile.close();
menu();
}
if (x=="2"){
system("cls");
string line;
ifstream myfile ("example.txt");
if (myfile.is_open())
{
while ( myfile.good() )
{
getline (myfile,line);
cout <<line << endl;
}
myfile.close();
getch();
menu();
}
else{ cout << "Unable to open file";
}
}
menu();
}
//encrypt data
void encrypt (string &e)
{
const char* tempCharArray = e.c_str();
for( int i=0; i<e.size(); ++i )
e[i] = tempCharArray[i]+75;
} // encrypt
//decrypt data
void decrypt (string &e)
{
const char* tempCharArray = e.c_str();
for( int i=0; i<e.size(); ++i )
e[i] = tempCharArray[i]-75;
} // decrypt
void Select(){
system("cls");
cout<<"Congratulations! You've either hacked in or cheated :P, please tell me how you\ndid it at http://www.cplusplus.com/forum/beginner/76573/(the link you should've gotten this from)\n";
getch();
}
|