Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace P4._PasswordValidator
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- char[] password = Console.ReadLine().ToCharArray();
- if (password.Length < 6 || password.Length > 10)
- {
- Console.WriteLine("Password must be between 6 and 10 characters");
- }
- int digitsInPassword = 0;
- int noLetterOrNumber = 0;
- for (int i = 0; i < password.Length; i++)
- {
- if (char.IsDigit(password[i]))
- {
- digitsInPassword++;
- }
- if (!char.IsLetter(password[i]) && !char.IsDigit(password[i]))
- {
- noLetterOrNumber++;
- }
- }
- if (noLetterOrNumber > 0)
- {
- Console.WriteLine("Password must consist only of letters and digits");
- }
- if (digitsInPassword < 2)
- {
- Console.WriteLine("Password must have at least 2 digits");
- }
- if (digitsInPassword >= 2 && password.Length >= 6 && password.Length <= 10 && noLetterOrNumber == 0)
- {
- Console.WriteLine("Password is valid");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement