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
|
#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 First(); //prompt to enter a password if there isn't one on record (i.e first time opening program)
void menu(); //currently unused
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();
}
Auth();
cout<<"To access the program, type program, or to change your password, type password.\n";
cin>>com;
/* if(com=="login")
{
Auth();
}*/
if(com=="password")
{
Passchange();
}
else if(com=="credits")
{
cout<<"written by ...";
}
else if(com=="exit")
{
cout<<"goodbye";
getch();
break;
}
else if(com=="program")
{
Members();
}
else if(com==com)
{
cout<<"Unknown command\n";
}
}
}
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:
{
getch();
break;
}
case '\b':
{
if(pass.size() != 0) //If the password string contains data, erase last character
{
cout << "\b \b";
pass.erase(first.size() - 1, 1);
}
break;
}
default:
{
if(isalnum(c) || ispunct(c))
{
pass += c;
cout << "*";
}
else if(!isprint(c)){
getch();
}
break;
}
};
}
while(c != '\r');
cout<<"\n";
Passfile.close();
if(pass==inpass)
{
cout<<"\nSuccess! Hit enter to continue to program";
getch();
Members();
}
else
{
cout<<"Wrong Password, please try again.";
getch();
main();
}
}
else
{
cout<<"Invalid Password";
getch();
main();
}
}
void First()
{
string first;
string firstconf;
do //Loop until 'Enter' is pressed
{
c = getch();
switch(c)
{
case 0:
{
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 << "*";
}
else if(!isprint(c)){
getch();
}
break;
}
};
}
while(c != '\r');
cout<<"\n";
system("cls");
cout<<"Confirm Password: ";
do //Loop until 'Enter' is pressed
{
c = getch();
switch(c)
{
case 0:
{
getch();
break;
}
case '\b':
{
if(firstconf.size() != 0) //If the password string contains data, erase last character
{
cout << "\b \b";
firstconf.erase(first.size() - 1, 1);
}
break;
}
default:
{
if(isalnum(c) || ispunct(c))
{
firstconf += c;
cout << "*";
}
else if(!isprint(c)){
getch();
}
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()
{
cout <<"Members area\n";
}
//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
|