Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _04_pass_validator
- {
- class Program
- {
- static void Main(string[] args)//100/100
- {
- string password = Console.ReadLine();//input word
- if (CheckIfIsLongEnough(password) + CheckIfItsOnlyLettersAndSymbols(password) + CheckIfItsAtLeastTwoDigits(password) == 3)
- {
- Console.WriteLine("Password is valid");
- }
- }
- static int CheckIfIsLongEnough(string password)//check for lenght of input
- {
- int control = 1;
- int counter = 0;
- for (int i = 0; i < password.Length; i++)
- {
- counter++;
- }
- if (counter < 6 || counter > 10)//not long enough
- {
- Console.WriteLine("Password must be between 6 and 10 characters");
- return control = 0;
- }
- else
- {
- return control;//long enough, return 1
- }
- }
- static int CheckIfItsOnlyLettersAndSymbols(string password)//check only letters and symbols
- {
- int control = 1;
- foreach (var symbol in password)
- {
- if (symbol < 48 || (symbol > 57 && symbol < 65) || (symbol > 90 && symbol < 97) || symbol > 122)//check ascii table
- {
- Console.WriteLine("Password must consist only of letters and digits");
- return control = 0;
- }
- }
- return control;//return 1
- }
- static int CheckIfItsAtLeastTwoDigits(string password)
- {
- int counter = 0;
- int control = 1;
- for (int i = 0; i < password.Length; i++)
- {
- if (password[i] == 48 || password[i] == 49 || password[i] == 50 || password[i] == 51 || password[i] == 52 || password[i] == 53 || password[i] == 54 || password[i] == 55 || password[i] == 56 || password[i] == 57)
- {
- counter++;
- }
- }
- if (counter < 2)
- {
- Console.WriteLine("Password must have at least 2 digits");
- return control = 0;
- }
- else
- {
- return control;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement