I am having two issues with the std::cin.getline() function.

Here is the relevant portion of my code:
Code:
std::cout << "Enter administrator password to unlock the database file" << std::endl;
		
while (!datafileVerified)
{
    std::cin.getline(adminPassword, MAX_PASSWORD_LENGTH+1);
    passLength = std::cin.gcount() - 1;
    datafileVerified = verifyDatafile(adminPassword);
    if (!datafileVerified) { std::cout << "Incorrect admin password, try again" << std::endl; }
}
MAX_PASSWORD_LENGTH is 16 so cin.getline() should accept 17 characters (16 + NULL).

First question:
When I input 16 characters or fewer cin.gcount() - 1 returns the correct number of characters (I don't want the NULL counted, hence the -1). So if I put in 16 characters gcount() - 1 gives returns 16. If; however, I input 17+ characters then gcount() -1 always returns 15. I put in more and it gives me less. What gives?

Second question:
When I put in an incorrect password, the call to verifyDatafile will fail and return 0. The variable datafileVerified is initialized to 0. If I input 16 or fewer characters this block of code works as expected, if the password is incorrect it continues to prompt the user for the password again. If; however, I input 17+ characters it skips the cin.getline() every time it goes through the loop and simply loops infinitely! What gives?

Thanks.