I have this Code written but I am having problems with the While loop I need it to recognize if the password has less then 5 characters and if there are spaces. I just cannot get it working for the spaces. Can anyone help??
#include <iostream>
#include <vector>
#include <string>
using namespace std;
string CheckPassword(string pass);
int main( )
{
string login;
string userName, password;
vector<string> v;
cout << "Enter your Username or 0 to stop:\n";
getline(cin,userName);
while ( userName != "0" )
{
password = CheckPassword(password);
login = userName + ", " + password;
v.push_back(login);
cout << "Enter your Username or 0 to stop:\n";
getline(cin,userName);
}
if (userName == "0")
{
cout << "The logins are:\n";
for (unsigned int i = 0; i < v.size( ); i++)
cout << v[i] << " " << "\n";
cout << endl;
}
system ("pause");
return 0;
}
string CheckPassword(string pass)
{
bool first = true;
do
{
if(!first)
{
cout << "Password must be greater than 5 characters and contain no spaces:\n";
}
cout << "Enter your Password:\n";
getline(cin,pass);
first = false;
}
while (pass.length() <= 5 || pass.find(' '));
return pass;
}