Input Username and Password

Hello,

I am currently in the process of making my first text-based RPG ( based on C++). I want to have users make an account before they start playing the RPG. Is there anyway to make a code that can store user-name's and passwords.

Thanks. (I'm a beginner)


- Code Assassin
Last edited on
well... what's your question?
Can you give me a code that stores user-name's and passwords?

- Code Assassin
I think this is what you are looking for http://www.cplusplus.com/forum/beginner/49365/
You can use map<string , string> like:

1
2
3
4
5
6
7
8
9
10
11
string user , pass;
map<string , string> mp;
//   register :
//   ... get username and password into "user" and "pass"
mp[user]=pass;

//  login :
//  ... get username and password into "user" and "pass"
if ( (!mp.find(user)==mp.end()) || (mp[user]!=pass) ) cout<<"LOGIN FAILED"; else cout<<"LOGIN SUCCESS";

system("pause");


For each value of string user (who has registered), mp[user] would return the password of that username. Just check if the login password is it.
Remember to use #include<map> at the beginning of your program, (and #include<iostream> and using namespace std; if you use my code)
Last edited on
Thanks to all who replied to this post. It helped a lot!

- Code Assassin
Hackinghorn,

I used your code and I got an error:

error: no match for 'operator!' in '!mp. std::map<_Key, _Tp, _Compare, _Alloc>::find [with _Key = std::string, _Tp = std::string, _Compare = std::less<std::string>, _Alloc = std::allocator<std::pair<const std::string, std::string> >](((const std::string&)((const std::string*)(& user))))'

I do not know how to solve this. Please help!

( I am on a Mac using Xcode)
Last edited on
Oh there's a mistake in my code. Remove the "!" before mp.find(user) in my code.
Tell me when U make it works
Last edited on
Thanks so much, hackinghorn! It works perfectly!

- Code Assassin
Topic archived. No new replies allowed.