Example #1
0
        //public override int MaxInvalidPasswordAttempts
        //{
        //    get { return WebSettings.MaxInvalidPasswordAttempts; }
        //}

        //public override int MinRequiredNonAlphanumericCharacters
        //{
        //    get { return WebSettings.MinRequiredNonAlphanumericCharacters; }
        //}

        //public override int MinRequiredPasswordLength
        //{
        //    get { return WebSettings.MinRequiredPasswordLength; }
        //}

        //public override int PasswordAttemptWindow
        //{
        //    get { return WebSettings.PasswordAttemptWindow; }
        //}

        //public override MembershipPasswordFormat PasswordFormat
        //{
        //    get { return MembershipPasswordFormat.Hashed; }
        //}

        //public override string PasswordStrengthRegularExpression
        //{
        //    get { return WebSettings.PasswordStrengthRegularExpression; }
        //}

        //public override bool RequiresQuestionAndAnswer
        //{
        //    get { return _requiresQuestionAndAnswer; }
        //}

        //public override bool RequiresUniqueEmail
        //{
        //    get { return true; }
        //}

        public override string ResetPassword(string username, string answer)
        {
            if (!EnablePasswordReset)
            {
                throw new NotSupportedException("Password reset is not enabled.");
            }

            DbEntryMembershipUser u = DbEntryMembershipUser.FindOne(p => p.UserName == username);

            if (answer == null && RequiresQuestionAndAnswer)
            {
                UpdateFailureCount(u, "passwordAnswer");

                throw new ProviderException("Password answer required for password reset.");
            }

            string newPassword =
                System.Web.Security.Membership.GeneratePassword(NewPasswordLength, MinRequiredNonAlphanumericCharacters);

            //    var u = DbEntryMembershipUser.FindOne(CK.K["UserName"] == username);
            if (u != null)
            {
                if (!RequiresQuestionAndAnswer || this.CheckPassword(u.PasswordAnswer, u))           //还有错误
                {
                    u.Password = this.EncodePassword(newPassword, u.PasswordFormat, u.PasswordSalt); ////StringHelper.Hash(p);
                    u.Save();
                    return(newPassword);
                }
            }
            return(null);
        }
Example #2
0
        private DbEntryMembershipUser FindUser(string username)
        {
            var u = DbEntryMembershipUser.FindOne(CK.K["UserName"] == username);

            if (u != null)
            {
                return(u);
            }
            return(null);
        }
Example #3
0
        private DbEntryMembershipUser FindUser(string username, string password)
        {
            var u = DbEntryMembershipUser.FindOne(CK.K["UserName"] == username);

            if (u != null && CheckPassword(password, u))
            {
                return(u);
            }
            return(null);
        }
Example #4
0
        public override string GetUserNameByEmail(string email)
        {
            var u = DbEntryMembershipUser.FindOne(CK.K["Email"] == email);

            if (u != null)
            {
                return(u.UserName);
            }
            return(null);
        }
Example #5
0
        public override string[] GetRolesForUser(string username)
        {
            var u  = DbEntryMembershipUser.FindOne(CK.K["UserName"] == username);
            var ls = new List <string>();

            foreach (DbEntryRole r in u.Roles)
            {
                ls.Add(r.Name);
            }
            return(ls.ToArray());
        }
Example #6
0
        /// <summary>
        /// 快速重置密码
        /// </summary>
        /// <param name="username">用户名</param>
        /// <param name="password"> </param>
        /// <returns>成功返回true,否则返回false</returns>
        public bool ResetPasswordX(string username, string password)
        {
            DbEntryMembershipUser u = DbEntryMembershipUser.FindOne(p => p.UserName == username);

            if (u != null)
            {
                u.Password = this.EncodePassword(password, u.PasswordFormat, u.PasswordSalt); ////StringHelper.Hash(p);
                u.Save();
                return(true);
            }
            return(false);
        }
Example #7
0
        public override bool ChangePassword(string username, string oldPassword, string newPassword)
        {
            var u = DbEntryMembershipUser.FindOne(CK.K["UserName"] == username);

            if (u != null && this.CheckPassword(oldPassword, u))
            {
                u.Password = this.EncodePassword(newPassword, int.Parse(u.PasswordSalt), u.PasswordSalt); //StringHelper.Hash(newPassword);
                u.Save();
                return(true);
            }
            return(false);
        }
Example #8
0
        public override bool IsUserInRole(string username, string roleName)
        {
            var u = DbEntryMembershipUser.FindOne(CK.K["UserName"] == username);

            foreach (DbEntryRole r in u.Roles)
            {
                if (r.Name == roleName)
                {
                    return(true);
                }
            }
            return(false);
        }
Example #9
0
        public override bool UnlockUser(string userName)
        {
            //    throw new Exception("The method or operation is not implemented.");
            var u = DbEntryMembershipUser.FindOne(p => p.UserName == userName);

            if (u != null)
            {
                u.IsLockedOut       = false;
                u.FailedAnswerCount = 0;
                u.FailedCount       = 0;
                u.Save();
                return(true);
            }
            return(false);
        }
Example #10
0
        /// <summary>
        /// 快速重置密码
        /// </summary>
        /// <param name="username">用户名</param>
        /// <returns>新密码</returns>
        public string ResetPassword(string username)
        {
            DbEntryMembershipUser u = DbEntryMembershipUser.FindOne(p => p.UserName == username);

            string newPassword =
                System.Web.Security.Membership.GeneratePassword(NewPasswordLength, MinRequiredNonAlphanumericCharacters);

            if (u != null)
            {
                u.Password = this.EncodePassword(newPassword, u.PasswordFormat, u.PasswordSalt); ////StringHelper.Hash(p);
                u.Save();
                return(newPassword);
            }
            return(null);
        }
Example #11
0
        public override MembershipUser GetUser(string username, bool userIsOnline)
        {
            var u = DbEntryMembershipUser.FindOne(CK.K["UserName"] == username);

            if (u != null)
            {
                if (userIsOnline)
                {
                    u.LastActivityDate = DateTime.Now;
                    u.Save();
                }
                return(u.ToMembershipUser());
            }
            return(null);
        }
Example #12
0
        public override bool DeleteUser(string username, bool deleteAllRelatedData)
        {
            if (deleteAllRelatedData)
            {
                throw new DataException("Not support deleteAllRelatedData");
            }
            var u = DbEntryMembershipUser.FindOne(CK.K["UserName"] == username);

            if (u != null)
            {
                u.Delete();
                return(true);
            }
            return(false);
        }
Example #13
0
        public override string GetPassword(string username, string answer)
        {
            if (!EnablePasswordRetrieval)
            {
                throw new ProviderException("Password Retrieval Not Enabled.");
            }

            if (PasswordFormat == MembershipPasswordFormat.Hashed)
            {
                throw new ProviderException("Cannot retrieve Hashed passwords.");
            }

            string password = "";

            var u = DbEntryMembershipUser.FindOne(CK.K["UserName"] == username);

            if (u == null)
            {
                throw new MembershipPasswordException("Can not find the user.");
            }
            if (u.IsLockedOut)
            {
                throw new MembershipPasswordException("The supplied user is locked out.");
            }

            if (RequiresQuestionAndAnswer && !CheckPassword(answer, u))
            {
                UpdateFailureCount(u, "passwordAnswer");

                throw new MembershipPasswordException("Incorrect password answer.");
            }

            if (PasswordFormat == MembershipPasswordFormat.Encrypted)
            {
                password = UnEncodePassword(password);
            }

            return(password);
        }