Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading;
- namespace ConsoleApp1
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("-------------WELCOME TO PASSWORD VALIDATOR---------------");
- Console.Write("Enter your password here: ");
- string password = Console.ReadLine();
- bool digitsValidation = DigitValidator(password);
- bool lengthValidation = LengthValidator(password);
- bool charsValidation = CharsValidator(password);
- if(digitsValidation == false)
- {
- Console.WriteLine("Password must have at least 2 digits.");
- }
- if(lengthValidation == false)
- {
- Console.WriteLine("Password must be between 6 and 10 characters.");
- }
- if(charsValidation == false)
- {
- Console.WriteLine("Password must consist only of letters and digits.");
- }
- if(charsValidation == true && lengthValidation == true && digitsValidation == true)
- {
- Console.WriteLine("The password is valid.");
- }
- }
- static bool DigitValidator(string password)
- {
- int digitCounter = 0;
- foreach(char i in password)
- {
- if (i >= '0' && i <= '9')
- {
- digitCounter++;
- }
- }
- if (digitCounter < 2)
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- static bool LengthValidator(string password)
- {
- if (password.Length < 6 && password.Length > 10)
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- static bool CharsValidator(string password)
- {
- bool validation = true;
- foreach(char i in password)
- {
- if((i>=48 && i<=57) || (i>=65 && i<=90) || (i>=97 && i <= 122))
- {
- continue;
- }
- else
- {
- validation = false;
- return validation;
- }
- }
- return validation;
- }
- }
- }
Add Comment
Please, Sign In to add comment