Register/Login program

I want write a program it can register and login how can i write this?
Last edited on
What code do you have currently?

Look into fstream.

(I'd also appreciate it if no one hopped in and wrote the whole program for the OP, let him/her figure it out)
As Avilius suggested, I will not write the whole program for you to use.

I assume that you have no code or very little code. Again as Avilius suggested, fstream would be a very useful tool for a program like this as you can then remember previous names from other run times of said program. As a recommendation from me, I would say look into arrays, in particular one that has two dimensions, one for the users name and the other for their password. That will help with matching users to their passwords and checking to see if they match.
ok thank you
std::map or std::unordered_map might be a good option to look into.
When registering, you'd just have to do something like
1
2
3
4
5
// Assuming 'userPasswords' is a std::map<std::string, std::string>
if (userPasswords.count(newUsername) > 0) // If user already exists
    // Yada yada, this user already exists, etc.
else
    userPasswords[newUsername] = newPassword;

and for logging, it'll be something like
1
2
3
4
5
6
if (userPasswords.count(username) == 0) // If user doesn't exist
    // Deal with nonexistant user here
else if (userPasswords[username] != password)
    // Wrong username/password combination
else
    // Logged in, yay. 
but when i close and run this, can program remember password and username
You'll have to save it to a text file and load it up again next time if you want the program to "remember".
If you disallow spaces in the username or password, you could simply just do
1
2
3
std::ofstream outFile("your filename goes here.txt", std::ios::trunc);
for (auto p : userPasswords)
    outFile << p.first << ' ' << p.second << '\n';
to save it, and then something like
1
2
3
4
std::ifstream loadFile("your filename goes here.txt");
std::string username, password;
while (loadFile >> username >> password)
    userPasswords[username] = password;
to load it back.
(Obviously, that's not a very secure way of saving it, but that's just an example of one way you could do it.)
thank you long double main
(Obviously, that's not a very secure way of saving it, but that's just an example of one way you could do it.)

I was going to post old code I had that used Sockets and MySQL (using the MySQL++ wrapper) to connect to a database on my old website, but this would be overwhelming due to throwing sockets, C++, and MySQL at him. It was a project I was doing for a game I scrapped (mainly because I took down the site) for usernames and high scores to see who was doing good out of the players. I think yours is way simpler though.
Topic archived. No new replies allowed.