示例#1
0
        public bool ValidateUserInput(ref User user)
        {
            Boolean emptyUsername;

            emptyUsername = _username.Equals(String.Empty);
            if (emptyUsername)
            {
                _errorMessage = "Username is empty";
                _actionOnError(_errorMessage);
                currentUserRole = UserRoles.ANONYMOUS;
                return(false);
            }

            Boolean emptyPassword;

            emptyPassword = _username.Equals(String.Empty);
            if (emptyPassword)
            {
                _errorMessage = "Password is empty";
                _actionOnError(_errorMessage);
                currentUserRole = UserRoles.ANONYMOUS;
                return(false);
            }

            if (_username.Length < 5)
            {
                _errorMessage = "The username is less than 5 symbols";
                _actionOnError(_errorMessage);
                currentUserRole = UserRoles.ANONYMOUS;
                return(false);
            }

            if (_password.Length < 5)
            {
                _errorMessage = "The password is less than 5 symbols";
                _actionOnError(_errorMessage);
                currentUserRole = UserRoles.ANONYMOUS;
                return(false);
            }

            user = UserData.isUserPassCorrect(_username, _password);

            if (user == null)
            {
                _errorMessage = "User is not exist";
                _actionOnError(_errorMessage);
                currentUserRole = UserRoles.ANONYMOUS;
                return(false);
            }

            currentUserRole     = (UserRoles)user.Role;
            currentUserUsername = (String)user.Username;
            Logger.LogActivity("Success Login");
            return(true);
        }
示例#2
0
        public bool ValudateUserInput(ref User user)
        {
            List <User> testUsers = UserData.TestUsers;

            Boolean emptyUserName;

            emptyUserName = Username.Equals(String.Empty);
            if (emptyUserName == true)
            {
                _currentUserRole = UserRoles.ANONYMOS;
                ErrorMessage     = "Не е посочено потребителско име\n";
                Program.printError(ErrorMessage);
                Console.ReadLine();
                actionOnError(ErrorMessage);
                return(false);
            }

            //------------------------------------
            Boolean emptyPassword;

            emptyPassword = Password.Equals(String.Empty);
            if (emptyPassword == true)
            {
                _currentUserRole = UserRoles.ANONYMOS;
                ErrorMessage     = "Не е посочена парола\n";
                Program.printError(ErrorMessage);
                Console.ReadLine();
                return(false);
            }

            //------------------------------------
            Boolean userNameAndPasswordMinLenght;


            userNameAndPasswordMinLenght = (Username.Length < 5 || Password.Length < 5);
            if (userNameAndPasswordMinLenght == true)
            {
                _currentUserRole = UserRoles.ANONYMOS;
                ErrorMessage     = "Дължината на потребителското име или паролата е по-малка от 5 символа\n";
                Program.printError(ErrorMessage);
                Console.ReadLine();
                return(false);
            }

            user = UserData.isUserPassCorrect(Username, Password);
            if (user != null)
            {
                _currentUserRole = (UserRoles)user.Role;
            }
            else
            {
                _currentUserRole = UserRoles.ANONYMOS;
                ErrorMessage     = "Не беше намерен потребител с такова потребителско име или парола !";
                Program.printError(ErrorMessage);
                return(false);
            }

            _currentUserUsername = user.Username;
            Logger.logActivity(Convert.ToString("Успешен login"));
            return(true);
        }