Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace _04._Password_Validator
- {
- class Program
- {
- static bool PasswordCheckCharacter(string input)
- {
- bool trueOrFalse = true;
- if(!(input.Length>=6 && input.Length<=10))
- {
- Console.WriteLine("Password must be between 6 and 10 characters");
- trueOrFalse = false;
- }
- return trueOrFalse;
- }
- static bool PasswordCheckLettersAndDigits(string input)
- {
- bool trueOrFalse = true;
- for (int i = 0; i < input.Length; i++)
- {
- char currentChar = input[i];
- if (!((currentChar >=48 && currentChar >= 57) || (currentChar >= 65 && currentChar <= 90) || (currentChar >= 97 && currentChar <= 122)))
- {
- Console.WriteLine("Password must consist only of letters and digits");
- trueOrFalse = false;
- }
- }
- return trueOrFalse;
- }
- static bool PasswordCheckDigits(string input)
- {
- bool trueOrFalse = false;
- int result;
- int counter = 0;
- for (int i = 0; i < input.Length; i++)
- {
- string character = input[i].ToString();
- if (int.TryParse(character, out result))
- {
- counter++;
- }
- }
- if(counter<2)
- {
- Console.WriteLine("Password must have at least 2 digits");
- trueOrFalse = true;
- }
- return trueOrFalse;
- }
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- PasswordCheckCharacter(input);
- PasswordCheckDigits(input);
- PasswordCheckLettersAndDigits(input);
- if(!(PasswordCheckCharacter(input) || PasswordCheckDigits(input) || PasswordCheckLettersAndDigits(input)))
- {
- Console.WriteLine("Password is valid");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment