빙수달 게임 개발 노트

[C++] 비밀번호 양식 판독기 본문

Programming/C++

[C++] 비밀번호 양식 판독기

빙수달 2024. 12. 18. 23:42
#include <iostream>
#include <cstring>
using namespace std;

int main()
{
	string password;		// string 비밀번호 변수 선언
	cin >> password;		// 비밀번호 입력

	int length = password.length();		// string 문법으로 비밀번호 길이 변수 선언 
	int num_count = 0;	// 숫자의 개수 변수 선언

	if (length < 8)		// 문자 길이가 8 미만이라면
	{
		cout << "InvalidPassword";
		return 0;
	}
	else				// 문자 길이가 8 이상이라면
	{
		for (int i = 0; i < length; i++)
		{
			if ('0' <= password[i] && password[i] <= '9')		// 0-9사이 숫자를 입력할 경우
			{
				num_count++;	// 숫자 개수 카운트 증가
			}
			else if (('a' <= password[i] && password[i] <= 'z') || ('A' <= password[i] && password[i] <= 'Z')) {}		// 알파벳 문자 입력할 경우
			else								// 숫자와 문자 이외의 특수문자가 입력되었다면
			{
				cout << "Invalid Password";
				return 0;
			}
		}			// for문을 어디서 닫아야할지 잘 생각해야한다. 
	}

	if (num_count < 2)		// 카운트된 숫자 개수가 2 미만이라면 유효하지 않은 비밀번호
	{
		cout << "Invalid Password";
		return 0;
	}

	cout << "Valid Password";
	return 0;
}