当前位置: 首页>>代码示例>>C#>>正文


C# UserManager.AddPassword方法代码示例

本文整理汇总了C#中UserManager.AddPassword方法的典型用法代码示例。如果您正苦于以下问题:C# UserManager.AddPassword方法的具体用法?C# UserManager.AddPassword怎么用?C# UserManager.AddPassword使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UserManager的用法示例。


在下文中一共展示了UserManager.AddPassword方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Recover_Click

        protected void Recover_Click(object sender, EventArgs e)
        {
            String user = User.Text;
            String email = Email.Text;
            if (user != "" && email != "")
            {

                ApplicationDbContext context = new ApplicationDbContext();
                String idUser = SqlCode.SelectForString("select id from AspNetUsers where UserName = '" + user + "'");
                ApplicationUser userr = context.Users.Find(idUser);

                if (userr.IsNotNull())
                {
                    if (userr.Email == email)
                    {
                        //gets user manager
                        UserManager manager = new UserManager();
                        //removes user pass
                        IdentityResult result = manager.RemovePassword(idUser);
                        //generates new pass
                        String newPass = (Guid.NewGuid().ToString("N").Substring(1, 8) + ".").Trim();
                        //updates the pass
                        result = manager.AddPassword(idUser, newPass);

                        if (result.Succeeded)
                        {
                            EmailClass.SendEmailRecover(email, newPass);
                            PlaceHolder1.Visible = true;
                            FailureText.Text = "Password of user changed email has been send";
                            Thread.Sleep(1000);
                            Response.Redirect("~/Account/Login.aspx");

                        }
                        else
                        {
                            PlaceHolder1.Visible = true;
                            FailureText.Text = "Error reseting the password";
                        }

                    }
                    else
                    {
                        PlaceHolder1.Visible = true;
                        FailureText.Text = "User does not match email!!";
                    }
                }
                else
                {
                    PlaceHolder1.Visible = true;
                    FailureText.Text = "User is invalid";
                }

            }
            else
            {
                PlaceHolder1.Visible = true;
                FailureText.Text = "User or password fields are empty!!";
            }
        }
开发者ID:PF2000,项目名称:AppLabRedes,代码行数:59,代码来源:Forgot.aspx.cs

示例2: SetPassword_Click

 protected void SetPassword_Click(object sender, EventArgs e)
 {
     if (IsValid)
     {
         // Create the local login info and link the local account to the user
         UserManager manager = new UserManager();
         IdentityResult result = manager.AddPassword(User.Identity.GetUserId(), password.Text);
         if (result.Succeeded)
         {
             Response.Redirect("~/Account/Manage?m=SetPwdSuccess");
         }
         else
         {
             AddErrors(result);
         }
     }
 }
开发者ID:segmentio,项目名称:asp.net-example,代码行数:17,代码来源:Manage.aspx.cs

示例3: setPassword_Click

        protected void setPassword_Click(object sender, EventArgs e)
        {
            if (IsValid)
            {
                // Create the local login info and link the local account to the user
                UserManager manager = new UserManager();

                var user = manager.FindById(User.Identity.GetUserId());

                IdentityResult result = manager.AddPassword(user.Id, password.Text);

                if (result.Succeeded)
                {
                    user.IsApproved = true;
                    manager.Update(user);

                    Response.Redirect("~/IdentityAccount/Manage.aspx?m=SetPwdSuccess");
                }
                else
                {
                    AddErrors(result);
                }
            }
        }
开发者ID:andreychizhov,项目名称:microsoft-aspnet-samples,代码行数:24,代码来源:Manage.aspx.cs

示例4: ResetPassword

        public ActionResult ResetPassword(ResetPasswordViewModel model)
        {
            var um = new UserManager<ApplicationUser>(
                new UserStore<ApplicationUser>(new ApplicationDbContext()));
            string userId = um.FindByName(model.UserName).Id;
            bool hasPassword = HasPassword(userId);
            ViewBag.HasLocalPassword = hasPassword;
            ViewBag.ReturnUrl = Url.Action("ResetPassword");
            if (hasPassword)
            {
                if (ModelState.IsValid)
                {
                    //IdentityResult result = await UserManager.ChangePasswordAsync(User.Identity.GetUserId(), model.OldPassword, model.NewPassword);
                    IdentityResult result = um.RemovePassword(userId);
                    if (result.Succeeded)
                    {
                        result = um.AddPassword(userId, model.NewPassword);
                        if (result.Succeeded)
                        {
                            return RedirectToAction("ResetPassword", new
                            {
                                Message = ManageMessageId.ChangePasswordSuccess
                               ,
                                userName = model.UserName
                            });
                        }
                        else
                        {
                            AddErrors(result);
                        }
                    }
                    else
                    {
                        AddErrors(result);
                    }
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
开发者ID:felixh0,项目名称:RequestManager,代码行数:41,代码来源:AccountController.cs

示例5: ChangeUserPassword

        public JsonResult ChangeUserPassword(string userId, string password)
        {
            UserManager<IdentityUser> userManager = new UserManager<IdentityUser>(new UserStore<IdentityUser>());
            userManager.RemovePassword(userId);
            userManager.AddPassword(userId, password);

            return Json(new { success = true });
        }
开发者ID:aviran3369,项目名称:Shallva,代码行数:8,代码来源:AdminController.cs

示例6: Edit

        public ActionResult Edit(EditAccountModel editModel)
        {
            var userManager = new UserManager<Account>(new UserStore<Account>(DbContext));
            Account editAccount = userManager.FindByName(editModel.UserName);

            if (editAccount == null)
            {
                return RedirectErrorPage();
            }

            // Kiểm tra tên tài khoản đã tồn tại hay chưa
            Account accountDb;
            if (editAccount.UserName != editModel.UserName)
            {
                accountDb = userManager.FindByName(editModel.UserName);
                if (accountDb != null)
                {
                    ModelState.AddModelError("UserName", "Tên tài khoản đã được sử dụng.");
                }
            }

            if (editAccount.Email != editModel.Email)
            {
                accountDb = userManager.FindByEmail(editModel.Email);
                if (accountDb != null)
                {
                    ModelState.AddModelError("Email", "Email đã được sử dụng.");
                }
            }
            if (editAccount.Profile.Identity != editModel.Identity)
            {
                accountDb = DbContext.Accounts.FirstOrDefault(s => s.Profile.Identity == editModel.Identity);
                if (accountDb != null)
                {
                    ModelState.AddModelError("Identity", "Mã số này đã được sử dụng.");
                }
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var acc = userManager.FindByName(editModel.UserName);
                    acc.Email = editModel.Email;
                    acc.PhoneNumber = editModel.PhoneNumber;
                    acc.Profile.BirthDate = editModel.BirthDate;
                    acc.Profile.FirstName = editModel.FirstName;
                    acc.Profile.LastName = editModel.LastName;
                    acc.Profile.Notes = editModel.Notes;
                    acc.Profile.Actived = editModel.Actived;
                    acc.Profile.Identity = editModel.Identity;
                    var result = userManager.Update(acc);
                    if (result.Succeeded)
                    {
                        if (!string.IsNullOrEmpty(editModel.Password))
                        {
                            userManager.RemovePassword(acc.Id);
                            userManager.AddPassword(acc.Id, editModel.Password);
                        }
                        if (editModel.Role == "Admin")
                        {
                            userManager.AddToRole(acc.Id, "Admin");
                            userManager.AddToRole(acc.Id, "Teacher");
                        }
                        else if (editModel.Role == "Teacher")
                        {
                            userManager.AddToRole(acc.Id, "Teacher");
                        }
                        else
                        {
                            userManager.AddToRole(acc.Id, "Student");
                        }

                        return Redirect(null);
                    }
                    ModelState.AddModelError("", "Đã có lỗi xảy ra. Vui lòng thử lại sau.");
                }
                catch
                {
                    ModelState.AddModelError("", "Đã có lỗi xảy ra. Vui lòng thử lại sau.");
                }
            }
            ViewBag.IsEdit = true;
            InitFormData(editModel);
            return View(editModel);
        }
开发者ID:xknguyen,项目名称:ETest,代码行数:86,代码来源:AccountController.cs

示例7: Rights_User_SetPassword

        public ActionResult Rights_User_SetPassword(SetUserPasswordViewModel model)
        {
            ModelState state = ModelState["NewPassword"];

            if (ModelState.IsValid)
            {
                var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(_identityDb));
                userManager.UserValidator = new UserValidator<ApplicationUser>(userManager) { AllowOnlyAlphanumericUserNames = false };
                
                var result2 = userManager.RemovePassword(model.userId);
                var result = userManager.AddPassword(model.userId, model.NewPassword);
                return RedirectToAction("Rights");
            }

            return View();
        }
开发者ID:InFlowBPM,项目名称:InFlow-BPMS,代码行数:16,代码来源:UserAdministrationController.cs

示例8: ResetPassword

        public ActionResult ResetPassword(FormCollection coll)
        {                    
            string[] randomAdjectives = {"thrutinn", "sleipur", "lodinn", "bonadur", "gradur", "brundadur", "siginn",
                                    "risinn", "lepjandi", "litill", "stor", "langur", "stuttur", "stinnur"};
            string[] randomNouns = {"angus", "besefi", "brusi", "lokur", "redur", "skondull", "tilli", "volsi", "skaufi"};

            var rand = new Random();
            int adjectiveNumber = rand.Next(0, 13);
            int nounNumber = rand.Next(0, 8);
            int randomNumber = rand.Next(1, 999);

            string newPass = randomAdjectives[adjectiveNumber] + randomNouns[nounNumber] + randomNumber.ToString();

            var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>());            
            var userService = new UserService();
            var email = coll["Email"];
            if(userService.getUserByEmail(email) != null)
            {
                var userId = userService.getUserByEmail(email).Id;
                userManager.RemovePassword(userId);
                userManager.AddPassword(userId, newPass);
                var message = new MailMessage();
                message.To.Add(new MailAddress(email));
                message.From = new MailAddress("Skilaboðaskjóðan");
                message.Subject = "Your password has been reset. ";
                message.Body = "<h2>Your password was reset on " + DateTime.Now.ToString() + "</h2>" + "<h3>Your new password is: " + newPass + "</h2>";
                message.IsBodyHtml = true;
                var smtp = new SmtpClient();

                var credential = new NetworkCredential
                {
                    UserName = "[email protected]",
                    Password = "smegma123"
                };
                smtp.Credentials = credential;
                smtp.Host = "smtp.gmail.com";
                smtp.Port = 587;
                smtp.EnableSsl = true;
                smtp.Send(message);
            }        
            return Redirect(HttpContext.Request.UrlReferrer.AbsoluteUri);
        
        }
开发者ID:dagurleo,项目名称:s_jodan,代码行数:43,代码来源:AccountController.cs

示例9: usersListview_ItemCommand

        protected void usersListview_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            if (e.CommandName == "SaveUserRoles")
            {
                string userId = e.CommandArgument.ConvertTo<string>();
                UserManager manager = new UserManager();
                CheckBoxList userRolesCheckboxList = e.Item.FindFirstControl<CheckBoxList>("userRolesCheckboxList");
                foreach (ListItem item in userRolesCheckboxList.Items)
                {
                    if (item.Selected)
                    {
                        manager.AddToRole(userId, item.Text);
                    }
                    else
                    {
                        manager.RemoveFromRole(userId, item.Text);
                    }
                }
                SuccessMessageUser = "Roles of user saved";
                successMessageUser.Visible = true;
            }
            else if (e.CommandName == "ChangePassword")
            {
                TextBox passwordTextBox = e.Item.FindFirstControl<TextBox>("NewPassword");
                TextBox confirmPasswordTextBox = e.Item.FindFirstControl<TextBox>("ConfirmNewPassword");

                if (!passwordTextBox.Equals("") && !confirmPasswordTextBox.Equals("") &&
                    passwordTextBox.Text == confirmPasswordTextBox.Text)
                {
                    string userId = e.CommandArgument.ConvertTo<string>();
                    UserManager manager = new UserManager();
                    IdentityResult result = manager.RemovePassword(userId);
                    result = manager.AddPassword(userId, passwordTextBox.Text);
                    if (result.Succeeded)
                    {
                        successMessageUser.Visible = true;
                        SuccessMessageUser = "Password of user changed";
                    }
                    else
                    {
                        successMessageUser.Visible = true;
                        AddErrors(result);
                        return;
                    }
                }
            }
        }
开发者ID:PF2000,项目名称:AppLabRedes,代码行数:47,代码来源:UserManagement.aspx.cs


注:本文中的UserManager.AddPassword方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。