ValidateUser() 공개 메소드

public ValidateUser ( string userName, string password ) : bool
userName string
password string
리턴 bool
예제 #1
0
        /// <summary>
        /// Verifican que usuario y password sean validos
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <param name="providerName">Nombre del proveedor de membership</param>
        /// <returns></returns>
        public static Boolean ValidateUser(string userName, string password, string providerName)
        {
            SqlMembershipProvider wProvider = GetSqlMembershipProvider(providerName);
            TechnicalException    te        = null;
            bool isValid = wProvider.ValidateUser(userName, password);

            if (!isValid)
            {
                MembershipUser user = wProvider.GetUser(userName, true);
                if (user != null)
                {
                    //User exists
                    if (!user.IsApproved)
                    {
                        //Account Unapproved
                        te         = new TechnicalException("Your account is not approved.");
                        te.ErrorId = "4011";
                        throw te;
                    }
                    else if (user.IsLockedOut)
                    {
                        //Account Locked

                        te         = new TechnicalException("Your account is locked.");
                        te.ErrorId = "4012";
                        throw te;
                    }
                    else
                    {
                        te         = new TechnicalException("Invalid username or password.");
                        te.ErrorId = "4013";
                        throw te;
                    }
                }
                else
                {
                    te         = new TechnicalException("Invalid username or password.");
                    te.ErrorId = "4013";
                    throw te;
                }
            }
            return(isValid);
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <param name="providerName"></param>
        /// <returns></returns>
        public static MembershipEnums CheckUserStatus(string userName, string password, string providerName)
        {
            MembershipEnums       status    = MembershipEnums.AccountUsernameAndPassword_IS_OK;
            SqlMembershipProvider wProvider = GetSqlMembershipProvider(providerName);

            bool isValid = wProvider.ValidateUser(userName, password);

            if (!isValid)
            {
                MembershipUser user = wProvider.GetUser(userName, true);
                if (user != null)
                {
                    //User exists
                    if (!user.IsApproved)
                    {
                        //Account Unapproved
                        status = MembershipEnums.AccountIsNotApproved;
                    }
                    else if (user.IsLockedOut)
                    {
                        //Account Locked
                        status = MembershipEnums.AccountIsLockedOut;
                    }
                    else
                    {
                        //Invalid username or password
                        status = MembershipEnums.InvalidUsernameOrPassword;
                    }
                }
                else
                {
                    status = MembershipEnums.InvalidUsernameOrPassword;
                }
            }
            return(status);
        }