Hi there this is my first time on a forum so I will try my best to make sense.
I am in the middle of a project and have hit a majour problem. I have a Cpp file that can add, delete, search and save data the problem I have is that I wish to add a password function to it but I have no idea how to go about doing that can anyone help me? please.
using namespace std;
struct employeerec{
string employeeID ; // array of employee ID numbers
string employee ; // array of employee names
string title ; // array of employee titles
} records [20]; // array of employees
int c;
int n;
int total=0;
void loademployeedata() // calls load data
{
ifstream myfile ("Employeefile.txt"); // opens file for input
if (myfile.is_open())
{
while (!myfile.eof()) // while not at end of file marker
{
getline (myfile, records[total].employeeID);
getline (myfile, records[total].employee);
getline (myfile, records[total].title);
total++;
}
myfile.close(); //close file
}
else cout << "Can't find file"; // if file not found
}
void Addemployee() // calls add employee
{
int c(-1);
bool found(false);
string reqemployeeID="";
do{
cout<< "Enter employee ID";
cin>> reqemployeeID;
if (reqemployeeID.length()!=14) cout<< "employee ID has invalid length. Please re-enter\n" << endl;
}while (reqemployeeID.length()!=14);
while ((c<total) && (!found))
{ c++;
if (reqemployeeID==records[c].employeeID) found=true;
myfile.close();
}
void Quit() {cout<<"Quit \n";} // calls quit program
void actonOption() // calls act on option
{
switch(option)
{
case 1:loademployeedata();break;
case 2:Addemployee();break;
case 3:Displayallemployees();break;
case 4:Searchinemployee();break;
case 5:Searchontitle();break;
case 6:SaveData();break;
case 9:Quit();break;
}
}
void displayMenu() // displays menu
{
cout << "1 Load Data \n";
cout << "2 Add employee \n";
cout << "3 Display all employees \n";
cout << "4 Search individual employee \n";
cout << "5 Search on Title \n";
cout << "6 Save Data \n";
cout << "9 Quit \n";
cin >> option;
while((option<1)||(option>9)) // loop to catch errors
{
if((option<1)||(option>9))
cout <<"Menu selection must be in range 1 to 9"<<endl;
cin >> option;
}
}
int main() // main body of program
{
while (option != 9){
displayMenu();
actonOption();
}
return 0;
no need to post this big code if you want help on something else.. :)
the first thing.. if you are adding your records in plain text then whats the need of password?? anyone can open the file and read it. first thing you should do is add all the data encrypted.. you can use so many algos for that like blowfish, rsa etc etc.. there are many.. this way one can see the data from your program.
if you are not interested in this idea than that's fine because second part is also related to encryption.. ;)
you can take the user input as password and can save it to some file, or if you are on windows then in windows registry after encrypting it. one thing which needs to be taken care of is if someone deletes the password file!!!
It makes some sense thank you but what I am aiming for is a log in function for when the program is ran you have to log in with a password and ID then the main menu is ran.