0

Username and password. Can't get the true false thing in this code to behave correctly.

PS it's long. I can't wrap my head around why i get "login successfull" when the username is wrong: So here's a very long code with an additional unessecary function call vy reference just for the fun of it: #include<iostream> #include<string> #include<vector> class Users { private: std::string m_username; std::string m_password; public: void setUsername(std::string username) { m_username = username; } void setPassword(std::string password) { m_password = password; } bool checkUsername(std::string username) { if (username == m_username) { return true; } else { return false; } } bool checkPassword(std::string password) { if (password == m_password) { return true; } else { return false; } } }; void setUsernameAndPassword(Users &user, std::string username, std::string password) { user.setUsername(username); user.setPassword(password); } void menu(std::vector<Users> &userVector) { std::cout << "1.New user\n2.Open user" << std::endl; int input; std::cin >> input; if (input == 1) { std::string username; std::string password; Users newUser; std::cout << "Enter username: "; std::getline(std::cin, username); std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); std::cout << "Enter password: "; std::getline(std::cin, password); //std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); setUsernameAndPassword(newUser, username, password); userVector.push_back(newUser); } if (input == 2) { //Print user id's std::cout << "Available users: " << std::endl; for (int n = 0; n < userVector.size(); n++)

c++

11/18/2016 3:28:59 PM

Ove Sletta

4 Answers

New Answer

+2

Post the link to the whole code here; the URL.

0

Crap, it's not enough characters here. I will put it in my codes. And you can copy it from there to explore it. this online compiler can't run it I think.

0

Here it is: https://code.sololearn.com/cMqsrZvQ6yuk/#cpp

0

I just took a look at the code in Visual Studio and when I entered a wrong password, it didn't accept it. So I guess it has already been fixed.