C++, Read username and passwords through file

Rahul++

SuperUser
Skilled
Hey guys,

I want to know how can we write the usernames and passwords in file just one time and later on they can be used for log in purpose..

I've some 5 objects of 1 class which can call the class only when the Username and password is correct. I've to use file handling for storing username and password.. I don't have much knowledge about file handling..

Can any c++ expert help me?

Thanks

rahul. :hap2:
 
its something like this..

- Declare a class with username & password.

- Create an object. (<object>)

- Input a record into the object. (ie username & password)

- Create a file stream.

- Use the following command to write the object into the file.

out.write((char)*)& <object>,sizeof(<object>));
 
^Yup, that should do it.
The data will be written in raw format and can be read the same way. What ever you do do not use any delimited file to write simple text.

You can even try to encrypt the password for additional security.
 
What dexBG suggested is the most simplistic way of achieving your purpose when your user profile class is in itself very simple.

A much better and cleaner way of doing it would be to overload insertion (<<) and extraction (>>) operators in your user record class. That way you have control over how your data is being written to the stream. For example you can exclude certain data members present in the class that are used only during runtime or put additional data that is not available as a data field in the class or encrypt only the password and more.
 
Back
Top