示例#1
0
        public bool ValidateUserInput(ref User user)
        {
            if (username.Length < 5 || password.Length < 5)
            {
                errorMsg = "Потребитеслкото име или парола са твърде къси.";
                action(errorMsg);
                return(false);
            }

            user = UserData.IsUserPassCorrect(username, password);
            if (user != null)
            {
                currentUserUsername = user.username;
                currentUserRole     = (UserRoles)user.role;
                Logger.LogActivity("Успешен Login");

                Logger.CountLatestLogins(user.username);
                return(true);
            }

            errorMsg        = "Потребителят не съществува.";
            currentUserRole = UserRoles.ANONYMOUS;

            action(errorMsg);
            Console.WriteLine(currentUserRole);

            return(false);
        }
        public bool ValidateUserInput(ref User us)//(ref User us)
        {
            //us.username = UserData.testUser.username;
            //us.password = UserData.testUser.password;
            //us.facNum = UserData.testUser.facNum;
            //us.role = UserData.testUser.role;

            //us = UserData.testUsers;
            //currentUserRole = (UserRoles)us.role;
            //us = new User();
            //us = UserData.IsUserPassCorrect(us.username, us.password);

            bool emptyUserName;

            emptyUserName = username.Equals(String.Empty);
            if (emptyUserName == true || username.Length < 5)
            {
                errorMessage = "You have not entered a username or it is too short.";
                errorMess(errorMessage);
                currentUserRole = UserRoles.Anonymous;
                return(false);
            }

            bool emptyUserPassword;

            emptyUserPassword = password.Equals(String.Empty);
            if (emptyUserPassword == true || password.Length < 5)
            {
                errorMessage = "You have not entered a password or it is too short.";
                errorMess(errorMessage);
                currentUserRole = UserRoles.Anonymous;
                return(false);
            }

            User proverka = UserData.IsUserPassCorrect(username, password);

            //if(UserData.IsUserPassCorrect(us.username, us.password)is User)
            if (proverka != null)
            {
                us = proverka;
                //User found = UserData.IsUserPassCorrect(us.username, us.password);
                currentUserRole = (UserRoles)us.role;
                //currentUserName = us.username;
                Logger.LogActivity("Succesful login!");
                return(true);
            }
            else
            {
                errorMessage = "There is no a such user!";
                errorMess(errorMessage);
                currentUserRole = UserRoles.Anonymous;
                return(false);
            }
        }
示例#3
0
 public bool ValidateUserInput(ref User user)
 {
     if (string.IsNullOrWhiteSpace(username) || string.IsNullOrEmpty(username))
     {
         errormesage         = "Username must be filled";
         CurrentUserRole     = UserRoles.ANONYMOUS;
         CurrentUserUsername = "******";
         err(errormesage);
         return(false);
     }
     if (username.Length < 5)
     {
         errormesage         = "Username must 5 or more symbols";
         CurrentUserRole     = UserRoles.ANONYMOUS;
         CurrentUserUsername = "******";
         err(errormesage);
         return(false);
     }
     if (string.IsNullOrWhiteSpace(password) || string.IsNullOrEmpty(password))
     {
         errormesage         = "Password must be filled";
         CurrentUserRole     = UserRoles.ANONYMOUS;
         CurrentUserUsername = "******";
         err(errormesage);
         return(false);
     }
     if (password.Length < 5)
     {
         errormesage         = "Password must 5 or more symbols";
         CurrentUserRole     = UserRoles.ANONYMOUS;
         CurrentUserUsername = "******";
         err(errormesage);
         return(false);
     }
     user = UserData.IsUserPassCorrect(username, password);
     if (user == null)
     {
         errormesage         = "Invalid Credentials";
         CurrentUserRole     = UserRoles.ANONYMOUS;
         CurrentUserUsername = "******";
         err(errormesage);
         return(false);
     }
     //user.FacNum = UserData.TestUser.FacNum;
     //user.Username = UserData.TestUser.Username;
     //user.Password = UserData.TestUser.Password;
     //user.UserRole = UserData.TestUser.UserRole;
     CurrentUserRole     = user.UserRole;
     CurrentUserUsername = user.Username;
     Logger.LogActivity("Successful Login");
     return(true);
 }
        public bool ValidateUserInput(User user)
        {
            User checkedPasswordUser = UserData.IsUserPassCorrect(this.Username, this.Password);

            if (user.Username.Length == 0)
            {
                CurrentUserRole = UserRoles.ANONYMOUS;
                Logger.LogActivity("Username is empty.");
                this.Exeption = "Username is empty.";
                this.ErrorAction(this.Exeption);
            }
            if (user.Password.Length == 0)
            {
                CurrentUserRole = UserRoles.ANONYMOUS;
                Logger.LogActivity("Password is empty.");
                this.Exeption = "Password is empty.";
                this.ErrorAction(this.Exeption);
            }
            if (user.Username.Length < 5)
            {
                CurrentUserRole = UserRoles.ANONYMOUS;
                Logger.LogActivity("Username should be longer than 5 symbols.");
                this.Exeption = "Username should be longer than 5 symbols.";
                this.ErrorAction(this.Exeption);
            }
            if (user.Password.Length < 5)
            {
                CurrentUserRole = UserRoles.ANONYMOUS;
                Logger.LogActivity("Password should be longer than 5 symbols.");
                this.Exeption = "Password should be longer than 5 symbols.";
                this.ErrorAction(this.Exeption);
            }
            if (!UserData.TestUsers.Any(x => x.Username == user.Username && x.Password == user.Password))
            {
                CurrentUserRole = UserRoles.ANONYMOUS;
                Logger.LogActivity($"No user with this login details: {user.Username} - {user.Password}");
                this.Exeption = $"No user with this login details: {user.Username} - {user.Password}";
                this.ErrorAction(this.Exeption);
            }
            try
            {
                checkedPasswordUser.Username = this.Username;
                checkedPasswordUser.Password = this.Password;
                CurrentUserRole     = checkedPasswordUser.Role;
                CurrentUserUsername = this.Username;
                Logger.LogActivity("Successful login");
            }
            catch
            {
            }
            return(true);
        }
 public bool ValidateUserInput(ref User user)
 {
     currentUserRole = UserRoles.ANONYMOUS;
     if (isEmptyInput(this._username))
     {
         this._errorMsg = "No username is entered.";
         this._actionOnError(this._errorMsg);
         return(false);
     }
     else if (isEmptyInput(this._password))
     {
         this._errorMsg = "No password is entered.";
         this._actionOnError(this._errorMsg);
         return(false);
     }
     else if (isUnderFiveSymbols(this._username))
     {
         this._errorMsg = "Entered username is under 5 symbols long.";
         this._actionOnError(this._errorMsg);
         return(false);
     }
     else if (isUnderFiveSymbols(this._password))
     {
         this._errorMsg = "Entered password is under 5 symbols long.";
         this._actionOnError(this._errorMsg);
         return(false);
     }
     else
     {
         List <User> users = UserData.TestUsers;
         user = UserData.IsUserPassCorrect(this._username, this._password);
         if (user == null)
         {
             this._errorMsg = "No user found.";
             this._actionOnError(this._errorMsg);
             return(false);
         }
         currentUserUsername = user.Username;
         currentUserRole     = (UserRoles)user.Role;
         Logger.LogActivity("Successfull login");
         return(true);
     }
 }
示例#6
0
        public bool ValidateUserInput(ref User user)
        {
            if (username.Equals(String.Empty) == true)
            {
                errorMessage = "The username is empty";
                actionOnError(errorMessage);
                return(false);
            }

            if (password.Equals(String.Empty) == true)
            {
                errorMessage = "The password is empty";
                actionOnError(errorMessage);
                return(false);
            }

            if (username.Length < 5)
            {
                errorMessage = "The username is less than 5 characters";
                actionOnError(errorMessage);
                return(false);
            }

            if (password.Length < 5)
            {
                errorMessage = "The password is less than 5 characters";
                actionOnError(errorMessage);
                return(false);
            }

            user = UserData.IsUserPassCorrect(username, password);
            if (user == null)
            {
                errorMessage = "There is no user with these username or password";
                actionOnError(errorMessage);
                return(false);
            }

            Logger.LogActivity("Successful login.");
            //currentUserRole = UserRole.ANONYMOUS;
            return(true);
        }
示例#7
0
        public bool ValidateUserInput(ref User user)
        {
            int usernameLen = username.Length;
            int passwordLen = password.Length;

            CurrentUserRole     = UserRoles.ANONYMOUS;
            CurrentUserUsername = "******";

            if (usernameLen == 0 || passwordLen == 0)
            {
                ErrorMessage = "Username or password is empty";
                actionOnError(ErrorMessage);
                return(false);
            }
            else if (usernameLen < 5 || passwordLen < 5)
            {
                ErrorMessage = "Username or password is less than 5 characters long";
                actionOnError(ErrorMessage);
                return(false);
            }

            User userResult = UserData.IsUserPassCorrect(username, password);

            if (userResult == null)
            {
                ErrorMessage = "Username or password is incorrect";
                actionOnError(ErrorMessage);
                return(false);
            }

            user.Username       = username;
            user.Password       = password;
            user.Role           = userResult.Role;
            user.FacultyNumber  = userResult.FacultyNumber;
            user.LastEnter      = DateTime.Now;
            CurrentUserRole     = userResult.Role;
            CurrentUserUsername = userResult.Username;

            Logger.LogActivity("Successful login");
            return(true);
        }
示例#8
0
        public bool ValidateUserInput(ref User user)
        {
            CurrentUserRole = UserRoles.ANONYMOUS;
            if (username.Equals(String.Empty))
            {
                errorMessage = "Не е посочено потребителско име";
                actionOnError(errorMessage);
                return(false);
            }
            if (password.Equals(String.Empty))
            {
                errorMessage = "Не е посочена парола";
                actionOnError(errorMessage);
                return(false);
            }

            if (username.Length < 4)
            {
                errorMessage = "Потребителското име е по-късо от 4 символа";
                actionOnError(errorMessage);
                return(false);
            }

            if (password.Length < 4)
            {
                errorMessage = "Паролата име е по-късо от 4 символа";
                actionOnError(errorMessage);
                return(false);
            }

            user = UserData.IsUserPassCorrect(username, password);
            if (user == null)
            {
                errorMessage = "Няма намерен потребител със зададените име и парола";
                actionOnError(errorMessage);
                return(false);
            }
            CurrentUserRole = user.Role;
            Logger.LogActivity("Успешен Login");
            return(true);
        }