Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace _04._Password_Validator
- {
- class Program
- {
- static void Main(string[] args)
- {
- string password = Console.ReadLine();
- bool isValidPassword = true;
- bool isValidChekPasswordLength= ChekPasswordLength(password, isValidPassword);
- bool isValidChekPasswordConsistLettersDigits= ChekPasswordConsistLettersDigits(password, isValidPassword);
- bool isValidChekPasswordLeastTwoDigits= ChekPasswordLeastTwoDigits(password, isValidPassword);
- ChekPasswordValid(isValidChekPasswordLength, isValidChekPasswordConsistLettersDigits, isValidChekPasswordLeastTwoDigits);
- }
- static bool ChekPasswordLength(string password, bool isValidPassword)
- {
- if (password.Length < 6 || password.Length > 10)
- {
- Console.WriteLine("Password must be between 6 and 10 characters");
- isValidPassword = false;
- }
- return isValidPassword;
- }
- static bool ChekPasswordConsistLettersDigits(string password, bool isValidPassword)
- {
- double passwordLettersDigits = 0;
- for (int i = 0; i < password.Length; i++)
- {
- char symbol = password[i];
- if ((password[i] >= 48 && password[i] <= 57) ||
- (password[i] >= 65 && password[i] <= 90) ||
- (password[i] >= 97 && password[i] <= 122))
- {
- passwordLettersDigits++;
- }
- }
- if (passwordLettersDigits != password.Length)
- {
- Console.WriteLine("Password must consist only of letters and digits");
- isValidPassword = false;
- }
- return isValidPassword;
- }
- static bool ChekPasswordLeastTwoDigits(string password, bool isValidPassword)
- {
- double passwordLeastTwoDigits = 0;
- for (int i = 0; i < password.Length; i++)
- {
- char symbol = password[i];
- if (password[i] >= 48 && password[i] <= 57)
- {
- passwordLeastTwoDigits++;
- }
- }
- if (passwordLeastTwoDigits < 2)
- {
- Console.WriteLine("Password must have at least 2 digits");
- isValidPassword = false;
- }
- return isValidPassword;
- }
- static void ChekPasswordValid(bool isValidChekPasswordLength,
- bool isValidChekPasswordConsistLettersDigits,
- bool ChekPasswordLeastTwoDigits)
- {
- if (isValidChekPasswordLength==true &&
- isValidChekPasswordConsistLettersDigits==true &&
- ChekPasswordLeastTwoDigits == true)
- {
- Console.WriteLine("Password is valid");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment