Archived

This topic is now archived and is closed to further replies.

phil05

Checking Password Problem in C++

Recommended Posts

phil05    100
WTF is wrong with this?
	// Checking Password
	char TEMP_PASSWORD[7];
	char PASSWORD[7] = "natale";

	std::cout << "Enter Your Password: ";
	std::cin.getline(TEMP_PASSWORD, 7, ''\n'');

	if (TEMP_PASSWORD != PASSWORD)
	{
		std::cout << "Invalid." << std::endl;
	}
	else
	{
		std::cout << "Correct." << std::endl;
	}
 

Share this post


Link to post
Share on other sites
prh99    520
quote:
Original post by philvaira
WTF is wrong with this?


// Checking Password
char TEMP_PASSWORD[7];
char PASSWORD[7] = "natale";

std::cout << "Enter Your Password: ";
std::cin.getline(TEMP_PASSWORD, 7, '\n');

if (TEMP_PASSWORD != PASSWORD)
{
std::cout << "Invalid." << std::endl;
}
else
{
std::cout << "Correct." << std::endl;
}




Try using the strcmp() or strncmp() functions since you're using and array of characters to hold your passwords. You'll need to include cstring to use them.

syntax:
int strcmp(const char *str1, const char *str2);

int strncmp(const char *str1, const char *str2, size_t count);

Both return zero if the strings are equal.




[edited by - prh99 on March 27, 2004 3:38:41 PM]

Share this post


Link to post
Share on other sites