コード例 #1
0
        public ActionResult PasswordChange(string oldPassword, string newPassword)
        {
            //Claim a ActiveDirectory object:User for further code.
            string          UserName = HttpContext.User.Claims.Where(user => user.Type == "UserName").First().Value;
            ActiveDirectory User     = new ActiveDirectory(UserName);

            //invoke ChangeOwnPassword methed, it will return if the operation is success.
            if (User.ChangeOwnPassword(oldPassword, newPassword))
            {
                ViewBag.PasswordState   = true;
                ViewBag.PasswordMessage = "Password Changed!";
                return(View("Password"));
            }
            else
            {
                ViewBag.PasswordState   = false;
                ViewBag.PasswordMessage = "Password Change Failed";
                return(View("Password"));
            }
        }