C++ Program using Passwords?

I would like to know how to go about making the program ask for a password? in quite new to c++ so thanks in advance!
Are you talking about a single, predefined password or a serial key?
Neither passwords or serial keys are especially secure in binary files due to the ability to debug programs. You can easily find a string, and you can find the algorithm behind a serial key. Your best bet would probably be to have the program connect to a server to verify the user if you want security.

If you just want to do it for fun, I suppose you could just declare a string and put the password in it. Then ask the user for input and compare the password string with the input.

Here's a quick example.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
std::string password = "mysecretpassword";
std::string input;

std::cout << "Enter password: ";
std::cin >> input;

if(input == password)
{       
        std::cout << "The password was correct!\n";
}       
else
{
        std::cout << "The password was wrong!\n";
}   
so how would i add that to full code? from the #include?
so how would i add that to full code? from the #include?



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>

int main()
{
	std::string password = "mysecretpassword";
	std::string input;

	std::cout << "Enter password: ";
	std::cin >> input;

	if(input == password)
	{       
		std::cout << "The password was correct!\n";
	}       
	else
	{
		std::cout << "The password was wrong!\n";
	}
	
	return 0;
}

Greatly Appreciated Thank you! :D
Topic archived. No new replies allowed.