Password Cracker (brute force)
This is a critique, and a rewrite of the code you showed, that is, the code for checking if a given password only contains characters from a given character set; for an actual brute force password cracker, see e.g. this  question.



I think you should look at the problem a bit differently.

Why don't you go through the characters in the password, and check if every character is in the set of allowed characters? 
If you get that every character of the password is in the set of allowed characters, then the password is valid, otherwise it isn't. 

I'd implement this in the following way.

#include&lt;algorithm&gt;
#include&lt;iostream&gt;
#include&lt;string&gt;
#include&lt;vector&gt;
#include&lt;set&gt;
#include&lt;numeric&gt;

const static std::set&lt;char&gt; charSet = {
    '%',
    'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
    'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
    '1','2','3','4','5','6','7','8','9','0'
};

bool checkPassword(const std::string password) {
  return std::accumulate( password.begin(), password.end(), true,
    [](bool acc, char c) { return acc &amp;&amp; charSet.find(c) != charSet.end(); } );
}

int main() {
  for (;;) {
    std::string password;
    std::cout &lt;&lt; "Enter password : ";
    std::cin &gt;&gt; password;
    std::cout &lt;&lt; "Your password is : " &lt;&lt; password &lt;&lt; std::endl;
    if(checkPassword(password)) {
      std::cout &lt;&lt; "VALID" &lt;&lt; std::endl &lt;&lt; std::endl;
    } else {
      std::cout &lt;&lt; "INVALID" &lt;&lt; std::endl &lt;&lt; std::endl;
    }
  }
  return 0;
}


This will work with passwords of any length. 
Set lookups have logarithmic complexity, so checking a password of length \$n\$ given a character set of size \$m\$ should be \$\mathcal O(n\cdot \log(m))\$.