loop for reading each file

hi.I'm facing a problem with how to make a code which reads the account number and password for each user ..... each user has his own file created when he register... so i need a code which checks the user info in each file .... PLEASE HELP !
how to make a code that loops through each file

this is the part concerning reading from a file

ifstream check;

check.open(x) ;
if ( check.is_open())
{
int count = 1;
int count2=0;
while(!check.eof())
{
getline (check,s);
if ( count == 7)
{
if (accountnumber != s)
{
cout << "Wrong account number !!.." << endl << endl ;
count2++;
}
}
else if ( count == 6)
{
if ( password != s )
{
cout << "Wrong Password !!..." << endl << endl ;
count2++;
}

}
count ++ ;

}
if (count2==0)
{
cout<<"WELCOME ..!!"<<endl<<endl;
}

}

check.close();

closed account (zwA4jE8b)
I've never done anything with file system stuff but I imagine if you put all your files into a folder then find a function or library that can populate a list with filenames then you can simply go through the list opening each file.

looks like on linux dirent.h will do it
Last edited on
Going though every file like you propose is insane. Try this.

unix systems keeps the password for all users in one file, however if each user has his own file, the simple way would be that each filename is the account number, within the file is the password.

of course this isn't very secure, but to make it work:
1. have the user enter his account number, and password
2. if the filename is .txt, you'll have to append that to the end of the account number string.
3. open the file, which is a string like "123456789.txt"
accountfile.open(accountnumber.c_str());
4. You only need to get one line
1
2
3
if (accountfile.is_open())
{
      getline (accountfile,line);

5. check to see if the password is what the user typed.
1
2
3
4
      if (securitykey==line)
      cout << " Welcome" <<  endl;
      else
      {cout << " Login incorrect" <<  endl;}


To improve security just chmod the password file with a value of 600 (owner only read & write access).
samuel Adams ....firstly thanks for your response ..and thanks for all
secondly i don't understand ... securitykey , line corresponds to which string ?


my strings are >> password //what is saved in the file ,,,
pass //what the user enters when he logs in
unique // the real account number
accountnumber // the account number he enters when he logs in
and the readable file >> is named check
Last edited on
Topic archived. No new replies allowed.