//private Utility_class_UserDAOMSSQL<Utility_class_User> _currentUserBaseMSSQLDAO = new Utility_class_UserDAOMSSQL<Utility_class_User>();

        public bool TryUserLogin(string userName, string password, out LoginToken <T> token)
        {
            bool           isUserExists = false;
            LoginToken <T> loginToken   = null;
            //List<Utility_class_User> allTheusers = (_currentUserBaseMSSQLDAO as Utility_class_UserDAOMSSQL<Utility_class_User>).GetAll();
            List <Utility_class_User> allTheusers = _currentUtility_Class_UserDAOMSSQL.GetAll();

            Dictionary <string, Func <Utility_class_User, IPoco> > correlation = new Dictionary <string, Func <Utility_class_User, IPoco> >();

            correlation.Add(typeof(Administrator).Name, (utility_user) => { return(_currentAdministratorDAOMSSQL.GetAdministratorByUserID(utility_user.ID)); });
            correlation.Add(typeof(Customer).Name, (utility_user) => { return(_currentCustomerDAOMSSQL.GetCustomerByUserID(utility_user.ID)); });
            correlation.Add(typeof(AirlineCompany).Name, (utility_user) => { return(_currentAirlineDAOMSSQL.GerAirlineCompanyByUserID(utility_user.ID)); });
            foreach (var s in allTheusers)
            {
                string s_username = string.Empty;
                if (s.USER_NAME.Length < 50)
                {
                    s_username = s.USER_NAME;
                }
                else
                {
                    s_username = EncryptionProvider.Decryprt(s.USER_NAME);
                }
                if (userName == s_username)
                {
                    //isUserExists = true;
                    string s_password = string.Empty;
                    if (s.PASSWORD.Length < 50)
                    {
                        s_password = s.PASSWORD;
                    }
                    else
                    {
                        s_password = EncryptionProvider.Decryprt(s.PASSWORD);
                    }
                    if (password == s_password)
                    {
                        //var actualUser = correlation[s.USER_KIND](s);
                        isUserExists = correlation.TryGetValue(s.USER_KIND, out Func <Utility_class_User, IPoco> funcMethod);
                        var actualUser = funcMethod(s);
                        loginToken            = new LoginToken <T>();
                        loginToken.ActualUser = actualUser as T;
                        loginToken.UserAsUser = s;
                    }
                    else
                    {
                        throw new WrongPasswordException(password);
                    }
                }
            }
            if (!isUserExists)
            {
                throw new UserNotFoundException(userName);
            }
            token = loginToken;
            return(isUserExists);
        }
Ejemplo n.º 2
0
 public Utility_class_User ValidateUser(string username, string password)
 {
     foreach (var s in _registeredUsersLst)
     {
         if (s.USER_NAME.Length > 50 && s.PASSWORD.Length > 50)
         {
             if (username == EncryptionProvider.Decryprt(s.USER_NAME) && password == EncryptionProvider.Decryprt(s.PASSWORD))
             {
                 _registeredUser.PASSWORD  = password;
                 _registeredUser.USER_NAME = username;
                 _registeredUser.USER_KIND = s.USER_KIND;
                 break;
             }
         }
     }
     return(_registeredUser);
 }
        /// <summary>
        /// If the user credantials are valid, returns true by "return" and instance of "Utility_class_User" with validated unencrypted user name nd password and user role by "out",
        /// in the "USER_NAME", "PASSWORD" and "USER_KIND" properties. Rest of the properties doesn't matter.
        /// In this methos "Utility_class_User" used differently, here it's just a data bearing model for validated user credentials.
        /// If the user credantials are not valid, returns false by "return" and null by "out".
        /// </summary>
        /// <param name="username">username</param>
        /// <param name="password">password</param>
        /// <param name="validatedUserModel">instance of "Utility_class_User" class with validated unecrypted user credentials. In this context used merely as a data bearing model for validated user credentials, only properties "USER_NAME", "PASSWORD" and "USER_KIND" are matters. "USER_KIND" bears user role.</param>
        /// <returns></returns>
        public bool ValidateUser(string username, string password, out Utility_class_User validatedUserModel)
        {
            bool   isUserValid = false;
            string s_USER_NAME = string.Empty;
            string s_PASSWORD  = string.Empty;

            foreach (var s in _registeredUsersLst)
            {
                if (s.USER_NAME.Length > 50)
                {
                    s_USER_NAME = EncryptionProvider.Decryprt(s.USER_NAME);
                }
                else
                {
                    s_USER_NAME = s.USER_NAME;
                }

                if (s.PASSWORD.Length > 50)
                {
                    s_PASSWORD = EncryptionProvider.Decryprt(s.PASSWORD);
                }
                else
                {
                    s_PASSWORD = s.PASSWORD;
                }


                if (username == s_USER_NAME && password == s_PASSWORD)
                {
                    _registeredUser.PASSWORD  = password;
                    _registeredUser.USER_NAME = username;
                    _registeredUser.USER_KIND = s.USER_KIND;
                    isUserValid = true;
                    break;
                }
            }
            if (!isUserValid)
            {
                _registeredUser = null;
            }
            validatedUserModel = _registeredUser;
            return(isUserValid);
        }
Ejemplo n.º 4
0
        public bool ChangeMyPassword(LoginToken <AirlineCompany> token, string oldPassword, string newPassword, out bool isPasswordWrong)
        {
            bool isChanged = false;

            if (CheckToken(token))
            {
                var    utility_user          = _utility_Class_UserDAO.GetUserByIdentifier(token.ActualUser);
                string utility_user_PASSWORD = string.Empty;
                if (utility_user.PASSWORD.Length > 50)
                {
                    utility_user_PASSWORD = EncryptionProvider.Decryprt(utility_user.PASSWORD);
                }
                else
                {
                    utility_user_PASSWORD = utility_user.PASSWORD;
                }


                if (utility_user_PASSWORD.Equals(oldPassword))
                {
                    _airlineDAO.Update(token.ActualUser, utility_user.USER_NAME, newPassword);
                }
                else
                {
                    isPasswordWrong = true;
                    //throw new WrongPasswordException(oldPassword);
                }

                var utility_userForChecking = _utility_Class_UserDAO.GetUserByIdentifier(token.ActualUser);
                if (utility_userForChecking.PASSWORD.Equals(newPassword))
                {
                    isChanged = true;
                }
            }
            isPasswordWrong = false;
            return(isChanged);
        }