Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace _04._Password_Validator
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- bool amountOfSynvoles = false;
- bool digitsAndLetters = false;
- bool countDigitis = false;
- amountOfSynvoles = SynvolAmount(input, amountOfSynvoles);
- digitsAndLetters = AreDigitsOrLetters(input, digitsAndLetters);
- countDigitis = AreDigitsTwoOrMore(input, countDigitis);
- if (amountOfSynvoles && digitsAndLetters && countDigitis)
- {
- Console.WriteLine("Password is valid");
- }
- }
- static bool AreDigitsTwoOrMore(string input, bool countDigitis)
- {
- int count = 0;
- for (int i = 0; i < input.Length; i++)
- {
- if (input[i] > 47 && input[i] < 58)
- {
- count++;
- }
- }
- if (count > 1) { countDigitis = true; }
- else { Console.WriteLine("Password must have at least 2 digits"); }
- return countDigitis;
- }
- static bool AreDigitsOrLetters(string input, bool digitsAndLetters)
- {
- if (input.All(char.IsLetterOrDigit))
- {
- digitsAndLetters = true;
- }
- else
- {
- Console.WriteLine("Password must consist only of letters and digits");
- }
- return digitsAndLetters;
- }
- static bool SynvolAmount(string input, bool amountOfSynvoles)
- {
- if (input.Length > 5 && input.Length < 11)
- {
- amountOfSynvoles = true;
- }
- if (!amountOfSynvoles)
- {
- Console.WriteLine("Password must be between 6 and 10 characters");
- }
- return amountOfSynvoles;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement