當前位置: 首頁>>代碼示例>>C#>>正文


C# SiteUser.IncrementPasswordAnswerAttempts方法代碼示例

本文整理匯總了C#中mojoPortal.Business.SiteUser.IncrementPasswordAnswerAttempts方法的典型用法代碼示例。如果您正苦於以下問題:C# SiteUser.IncrementPasswordAnswerAttempts方法的具體用法?C# SiteUser.IncrementPasswordAnswerAttempts怎麽用?C# SiteUser.IncrementPasswordAnswerAttempts使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在mojoPortal.Business.SiteUser的用法示例。


在下文中一共展示了SiteUser.IncrementPasswordAnswerAttempts方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: GetPassword

        public override string GetPassword(string userName, string passwordAnswer)
        {
            /*
             * Takes, as input, a user name and a password answer and returns that user's password.
             * If the user name is not valid, GetPassword throws a ProviderException. Before retrieving
             * a password, GetPassword verifies that EnablePasswordRetrieval is true.
             * If EnablePasswordRetrieval is false, GetPassword throws a NotSupportedException.
             * If EnablePasswordRetrieval is true but the password format is hashed, GetPassword
             * throws a ProviderException since hashed passwords cannot, by definition, be retrieved.
             * A membership provider should also throw a ProviderException from Initialize if
             * EnablePasswordRetrieval is true but the password format is hashed. GetPassword also
             * checks the value of the RequiresQuestionAndAnswer property before retrieving a password.
             * If RequiresQuestionAndAnswer is true, GetPassword compares the supplied password
             * answer to the stored password answer and throws a MembershipPasswordException if
             * the two don't match. GetPassword also throws a MembershipPasswordException if the
             * user whose password is being retrieved is currently locked out.
             */

            SiteSettings siteSettings = GetSiteSettings();

            if (!siteSettings.AllowPasswordRetrieval)
            {
                throw new MojoMembershipException(
                    ResourceHelper.GetMessageTemplate("PasswordRetrievalNotEnabledMessage.config")
                    );
            }

            if ((userName != null) && (siteSettings != null))
            {
                SiteUser siteUser = new SiteUser(siteSettings, userName);
                if (siteUser.UserId > -1)
                {
                    if (siteUser.IsLockedOut)
                    {
                        throw new MembershipPasswordException(
                            ResourceHelper.GetMessageTemplate("UserAccountLockedMessage.config"));
                    }

                    if (siteUser.IsDeleted)
                    {
                        throw new MembershipPasswordException(
                            ResourceHelper.GetMessageTemplate("UserNotFoundMessage.config"));
                    }

                    bool okToGetPassword = false;
                    if (siteSettings.RequiresQuestionAndAnswer)
                    {
                        if ((passwordAnswer != null) && (PasswordAnswerIsMatch(passwordAnswer, siteUser.PasswordAnswer)))
                        {
                            okToGetPassword = true;
                        }
                        else
                        {
                            if (siteSettings.MaxInvalidPasswordAttempts > 0)
                            {
                                siteUser.IncrementPasswordAnswerAttempts(siteSettings);

                                if (WebConfigSettings.LockAccountOnMaxPasswordAnswerTries)
                                {
                                    if (siteUser.FailedPasswordAnswerAttemptCount >= siteSettings.MaxInvalidPasswordAttempts)
                                    {
                                        siteUser.LockoutAccount();
                                    }
                                }

                            }
                        }

                    }
                    else
                    {
                        okToGetPassword = true;
                    }

                    if(okToGetPassword)
                    {
                        if (siteSettings.RequirePasswordChangeOnResetRecover)
                        {
                            siteUser.MustChangePwd = true;
                            siteUser.Save();
                        }

                        switch(PasswordFormat)
                        {
                            case MembershipPasswordFormat.Clear:

                                return siteUser.Password;

                            case MembershipPasswordFormat.Encrypted:

                                try
                                {
                                    if (siteUser.PasswordSalt.Length > 0)
                                    {
                                        return UnencodePassword(siteUser.Password, MembershipPasswordFormat.Encrypted).Replace(siteUser.PasswordSalt, string.Empty);
                                    }
                                    else
                                    {
                                        return UnencodePassword(siteUser.Password, MembershipPasswordFormat.Encrypted);
                                    }
//.........這裏部分代碼省略.........
開發者ID:joedavis01,項目名稱:mojoportal,代碼行數:101,代碼來源:mojoMembershipProvider.cs


注:本文中的mojoPortal.Business.SiteUser.IncrementPasswordAnswerAttempts方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。