-4
ofstream shadow,salt;
ifstream shadowread,saltread;

login:
cout << "Enter your login id" << endl;
cin >> user;
shadowread.open("salt.txt");

while(!shadowread.eof())
{
    getline(shadowread, usercmp, ":");
    shadowread.close();
    if (usercmp == user)
    {
        int captcha = rand() % 10;
        int read;
        cout << "Enter the captcha" << captcha << endl;
        cin >> read ;
        if (captcha == read)
        {
            goto enterpw;
        }
        else
            goto login;
    }
}

txt file

root:password:2

How to read the password category?

muXXmit2X
  • 2,745
  • 3
  • 17
  • 34
  • after double click the txt file the file format is like /etc/shadow .how to just read the column – Teh Win Sam Aug 16 '18 at 05:31
  • Indent your code properly. –  Aug 16 '18 at 05:33
  • 3
    Welcome to StackOverflow Teh Win Sam. Please take the [tour] and read [ask]. – Yunnosch Aug 16 '18 at 05:35
  • 1
    You fail to explain what you are trying to do (no context). You fail to explain what the code should do. The code contains a [`while eof` loop](https://stackoverflow.com/q/5605125/3545273). The code mixes `getline` and stream extractor (`>>`) with no explaination (not even a comment). The code uses goto when it could probably use a loop. I'm sorry, but that is too much for a single question... Please read [ask]... – Serge Ballesta Aug 16 '18 at 06:17
  • There is a list of good books [here](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). – molbdnilo Aug 16 '18 at 06:41

1 Answers1

0

Once you read the line , with "find" and "substr" , you can get the password details as,

    int idx = 0, cnt=0;
    int pos = usercmp.find(":");
    while(pos != string::npos) {
        cnt++;
        auto val = usercmp.substr(idx,pos-idx);
        if(cnt == 3) cout << "val => " << val << endl;
        idx = pos+1;
        pos = usercmp.find(":",idx);
    }
Somesh
  • 82
  • 8