Example #1
0
        public static User Login(User[] users, ValidationSevice validationSevice)
        {
            while (true)
            {
                Console.Write("Enter email: ");
                string email = Console.ReadLine();

                if (!validationSevice.ValidateEmail(email))
                {
                    Console.WriteLine("Enter valid email.");
                    continue;
                }

                User user = FindUser(email, users);
                if (user == null)
                {
                    Console.WriteLine("User does not exists");
                    continue;
                }

                // TODO: add 3 tries for password

                Console.WriteLine("Enter password");
                string password = Console.ReadLine();
                if (user.Password != password)
                {
                    Console.WriteLine("Password is incorect.");
                    continue;
                }

                return(user);
            }
        }
Example #2
0
        public static User Register(User[] users, ValidationSevice validationSevice)
        {
            string email    = EnterEmail(validationSevice, users);
            string password = EnterPassword(validationSevice);

            return(CreateUser(email, password));
        }
Example #3
0
        private static string EnterPassword(ValidationSevice validationSevice)
        {
            while (true)
            {
                Console.WriteLine("Enter password. Password should contain 1 upper charater, 1 digit and should be 8 letter long");
                string password = Console.ReadLine();
                if (!validationSevice.ValidatePassword(password))
                {
                    Console.WriteLine("Enter valid password");
                    continue;
                }

                return(password);
            }
        }
Example #4
0
        private static string EnterEmail(ValidationSevice validationSevice, User[] users)
        {
            while (true)
            {
                Console.WriteLine("Enter email: ");
                string email = Console.ReadLine();
                if (!validationSevice.IsEmailUnique(email, users))
                {
                    Console.WriteLine("Email is already taken.");
                    continue;
                }

                if (!validationSevice.ValidateEmail(email))
                {
                    Console.WriteLine("Please enter valid mail.");
                    continue;
                }

                return(email);
            }
        }