function - How to keep looping until password meets condition in C++? -


i trying continue loop ask user enter new password until condition met. new password compared old password passed function. condition is, first half of new , old password can't same , second half of new , old password can't same. if condition met, old password gets changed new password. have far, works once , doesn't keep looping ask new password until condition met. there way make keep looping until new password passes condition?

bool changepasswordintonewpw(string& oldpassword) { string newpw; int sizen; int half; int lengtholdpw; int lengthnewpw;   {     cout << "enter new password must meet condition: ";     getline(cin, newpw);       lengthnewpw = newpw.length();     lengtholdpw = oldpassword.length();     if (lengthnewpw < lengtholdpw)     {         sizen = lengthnewpw;     }     else if (lengtholdpw < lengthnewpw)     {         sizen = lengtholdpw;     }     else         sizen = lengtholdpw;      half = sizen / 2;      if( ( oldpassword.size() <= 2 ) ||         ( ( oldpassword.substr( 0, half ) != newpw.substr( 0, half ) ) &&           ( oldpassword.substr( oldpassword.size() - half ) != newpw.substr( newpw.size() - half ) ) ) )         return true;            {             cout << "the new password cannot start or end " << half                  << " or more characters same old password" << endl << endl;            }   } while (( oldpassword.size() <= 2 ) ||         ( ( oldpassword.substr( 0, half ) != newpw.substr( 0, half ) ) &&           ( oldpassword.substr( oldpassword.size() - half ) != newpw.substr( newpw.size() - half ) ) ) );       oldpassword = newpw;     return true;   } 

your while condition same condition password true. have set while password not true. add ! while condition.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -