name and pass check

Hi :)
I'm very new at this and I guess I put quite difficult task to do but whatever :P

I'm trying to create a login check for my programe. When you create a new user it will write it down in a file passwd like: login|password and new line etc.
So I want to create a check for this. Like when you want to log in, you will enter login and pass and it will search in passwd file if it's correct :) Got the ide? :P
I did this already in bash. It's easy to do there :) but I want to do it in C++ too. So basically I need search engine to go through the file. I have sth like that, it just go through the file and write it down:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <fstream>
using namespace std;

int main () {
  string line;
  ifstream pass_file ("passwd");
  if (pass_file.is_open())
  {
    while ( pass_file.good() )
    {
      getline (pass_file,line);
      cout << line << endl;
    }
  }
  return 0;
}

But, I want it to do this: what it takes first line to variable "line" I want to divide it into "login|pass" Can I do that somehow? like in bash: $login|$pass so simple :))
and after that I want to compare it with what the user entered. I hope you know what I mean :) pls help me :)
You have your line, now you need to split it up into username and password.

Since | is the delimiting character let's search for it:
size_t split = line.find('|');

now we create new strings for the name and password:
1
2
string name(line, 0      , split-1);
string pass(line, split+1);


Tada!
Last edited on
WOW thanks :)))
working sweet :)
Topic archived. No new replies allowed.