I'm having the hardest time figuring out why my password check loop won't exit after excepting valid input. Can someone help?
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main( )
{
vector<string> credentials;
string login;
string userName;
string password;
string CheckPassword (string password);
cout << "Enter user name or enter 0 to stop." << endl;
getline(cin, userName);
while (userName != "0")
{
CheckPassword(password);
}
password = CheckPassword (password);
login = userName + password;
credentials.push_back(login);
for (unsigned int i = 0; i < credentials.size( ); i++)
cout << credentials[i] <<" ";
cout << endl;
return 0;
}
string CheckPassword (string password)
{
do
{
cout << "Enter a valid password." << endl;
getline(cin, password);
}
while (password.length ( ) <= 4);
cout << "Password accepted." << endl;
return password;
}