Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace methods_exerci
- {
- class Program
- {
- static void Main(string[] args)
- {
- string password = Console.ReadLine();
- bool isValid = true;
- isValid = PasswordLength(password, isValid);
- isValid = IsLetterOrDigit(password, isValid);
- isValid = IsDigit(password, isValid);
- PasswordIsValid(isValid);
- }
- static bool PasswordLength(string password, bool isValid)
- {
- if (password.Length < 6 || password.Length > 10)
- {
- Console.WriteLine("Password must be between 6 and 10 characters");
- isValid = false;
- }
- return isValid;
- }
- static bool IsLetterOrDigit(string password, bool isValid)
- {
- for (int i = 0; i < password.Length; i++)
- {
- if (!Char.IsLetterOrDigit(password[i]))
- {
- Console.WriteLine("Password must consist only of letters and digits");
- isValid = false;
- break;
- }
- }
- return isValid;
- }
- static bool IsDigit(string password, bool isValid)
- {
- int digit = 0;
- for (int i = 0; i < password.Length; i++)
- {
- if (Char.IsDigit(password[i]))
- {
- digit++;
- }
- }
- if (digit < 2)
- {
- Console.WriteLine("Password must have at least 2 digits");
- isValid = false;
- }
- return isValid;
- }
- static void PasswordIsValid(bool isValid)
- {
- if (isValid)
- {
- Console.WriteLine("Password is valid");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment