DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Password Check

11.13.2008
| 3569 views |
  • submit to reddit
        // description of your code here

#include <iostream>
#include <string>
using namespace std;

void main()
{
	int counter = 0;
    string pw;
	string default_pw = "1234"; //預設密碼 

	while(true)
	{
		cout<<"Enter your password:";
		cin>>pw;

		if(pw.compare(default_pw) == 0)
		{
			cout<<"驗證通過";
			break;
		}else if(++counter == 3)
		{
			cout<<"驗證失敗";
			break;
		}
	}
	
	cout<<endl;
	system("pause");
}.
    

Comments

Snippets Manager replied on Tue, 2007/06/05 - 11:43am

if(pw.compare(default_pw) == 0) should be written as if(pw == default_pw)