示例#1
0
        public ActionResult ChangePassword(Models.ChangePassword model)
        {
            var   emailID = User.Identity.Name.ToString();
            Users obj     = dbobj.Users.Where(x => x.EmailID == emailID).FirstOrDefault();

            if (ModelState.IsValid)
            {
                if (String.Compare(model.OldPassword, obj.Password) == 0)
                {
                    obj.Password     = model.NewPassword;
                    obj.ModifiedDate = DateTime.Now;

                    dbobj.Entry(obj).State = System.Data.Entity.EntityState.Modified;
                    dbobj.SaveChanges();

                    FormsAuthentication.SignOut();
                    return(RedirectToAction("Login"));
                }
                else
                {
                    ModelState.AddModelError("OldPassword", "OldPassword Is Incorrect");
                }
            }
            return(View());
        }
示例#2
0
        public IHttpActionResult ChangeAdminPassword(Models.ChangePassword cp)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest("Passed information isn't valid."));
                }

                var userStore   = new UserStore <IdentityUser>(new UserDBContext());
                var userManager = new UserManager <IdentityUser>(userStore);

                // Let's find the user so we can't change the password
                var user = userManager.FindById(Request.GetOwinContext().Authentication.User.Identity.GetUserId());
                userManager.ChangePassword(user.Id, cp.OldPassword, cp.NewPassword);

                updatePassword(user); // update the user's password in NewsDB

                return(Ok());
            }
            catch (Exception ex)
            {
                logger.Error(ex, "An admin attempted to change their password and it threw an exception: " + ex.Message);
                return(BadRequest("Something went worng while changing the password"));
            }
        }
        public async Task <IActionResult> Confirmation(Models.ChangePassword args)
        {
            ModelState.Clear();

            if (args.NewPassword != args.ReEnterNewPassword)
            {
                ModelState.AddModelError(string.Empty, "New password & re-enter new password must match.");
                return(View(args));
            }
            else
            {
                var salt = Core.Crypto.GenerateSalt();
                var enc  = Core.Crypto.Hash(args.NewPassword, salt);

                var rec = await new BLL.User(unitOfWork).Get(new EF.User {
                    UserId = args.UserId
                });
                rec.PasswordHash        = enc;
                rec.PasswordSalt        = Convert.ToBase64String(salt);
                rec.LastPasswordChanged = DateTime.Now;
                rec.DateConfirmed       = DateTime.Now;
                rec.ConfirmationCode    = null;
                rec.ConfirmationExpiry  = null;
                rec.DateInactive        = null;

                await new BLL.User(unitOfWork).Edit(rec);

                await AddClaimsAndSignIn(rec);

                TempData["notice"] = "Successfully changed password";

                return(RedirectToAction("Index", "Main"));
            }
        }
        public async Task <IActionResult> ChangePassword([FromBody] Models.ChangePassword args)
        {
            var user     = HttpContext.Items["EndUser"] as EF.EndUser;
            var bll_user = endUserBusiness;

            // Validate current password
            var salt      = user.PasswordSalt;
            var saltBytes = Convert.FromBase64String(salt);

            if (Core.Crypto.Hash(args.CurrentPassword, saltBytes) == user.PasswordHash)
            {
                var newSalt = Core.Crypto.GenerateSalt();
                user.PasswordSalt = Convert.ToBase64String(newSalt);
                user.PasswordHash = Core.Crypto.Hash(args.NewPassword, newSalt);

                await bll_user.Edit(user);

                return(Ok());
            }
            else
            {
                return(new ObjectResult("Invalid password.")
                {
                    StatusCode = 403,
                    Value = "Invalid password."
                });
            }
        }
示例#5
0
 public ActionResult ChangePassword(Models.ChangePassword c)
 {
     if (ModelState.IsValid)
     {
         ViewModel.Account.ChangePassword cp = new ViewModel.Account.ChangePassword();
         ViewBag.msg = cp.SavePassword(c);
     }
     return(View());
 }
示例#6
0
        public bool UpdatePassword(Models.ChangePassword blotterCP)
        {
            bool status = false;

            if (ModelState.IsValid)
            {
                status = DAL.UpdateUserPassword(blotterCP.UserId, blotterCP.Password, blotterCP.NewPassword);
            }
            return(status);
        }
        public ActionResult ChangePassword(int uid)
        {
            UserModel      userModel = new UserModel();
            user_info      ui        = userModel.GetUserInfo(uid);
            ChangePassword cp        = new Models.ChangePassword();

            cp.Status      = ui.ui_status;
            ViewBag.UserId = uid;
            return(View(cp));
        }
示例#8
0
        public ActionResult ChangePassword(Models.ChangePassword model)
        {
            Session["changePassword"] = null;
            try
            {
                var    entities = new Job_Candidate_Application_Entities();
                string email    = Request["email"];
                if (ModelState.IsValid)
                {
                    string currentPassword = null;
                    if (User.Identity.IsAuthenticated)
                    {
                        email           = User.Identity.Name;
                        currentPassword = model.CurrentPassword;

                        var verifyCurrentPassword = entities.Tbl_Users.Find(email).Password;

                        if (verifyCurrentPassword != Helpers.SHA1.Encode(currentPassword))
                        {
                            ModelState.AddModelError("", "Current password is incorrect! Try again");
                            return(View(model));
                        }
                    }
                    string password = model.Password;
                    guid = Guid.NewGuid();      //update change to invalidate change password link in the email

                    //update password in the database
                    if (model.UpdatePassword(email, currentPassword, password, guid.ToString()))
                    {
                        model.EmailId             = email;
                        model.CurrentPassword     = null;
                        model.Password            = null;
                        model.ConfirmPassword     = null;
                        Session["changePassword"] = "******";
                        return(View(model));
                    }
                }
                else
                {
                    // ModelState.AddModelError("", "Error occured! Try again!");
                    model.EmailId = email;
                    return(View(model));
                }
            }
            catch (Exception ex)
            {
                //Session["changePassword"] = ex.Message;
                ModelState.AddModelError("", "Error occured! Try again!");
                return(View(model));
            }

            //something happened. display page again
            return(View(model));
        }
示例#9
0
        public ActionResult ChangePassword()
        {
            Session["changePassword"] = null;
            try
            {
                string guid     = Request["id"];
                string email    = Request["email"];
                var    entities = new Job_Candidate_Application_Entities();

                if (!User.Identity.IsAuthenticated && guid != null && email != null)
                {
                    var    model       = new Models.ChangePassword();
                    var    verifyEmail = entities.Tbl_Users.Find(email);
                    string isGuidValid = verifyEmail.User_Guid;

                    if (guid != isGuidValid)
                    {
                        ModelState.AddModelError("", "Link is not valid.");
                        return(View(model));
                    }
                    else if (verifyEmail != null)
                    {
                        //user has not confirmed yet
                        if (email != null && guid != null)
                        {
                            model.EmailId = email;
                            return(View(model));
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "Email ID could not be found!");
                        return(View(model));
                    }
                }
                else if (User.Identity.IsAuthenticated)
                {
                    return(View());
                }
                else
                {
                    return(RedirectToAction("Index", "Home"));
                }
            }
            catch (Exception ex)
            {
                Session["verify"] = ex.Message;
            }

            //something happened. redirect user to home screen
            return(RedirectToAction("Index", "Home"));
        }
示例#10
0
        public ActionResult ChangePassword()
        {
            if (Session["LogonAdmin"] != null)
            {
                Models.ChangePassword model = new Models.ChangePassword();

                return(View(model));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
示例#11
0
 public ActionResult changePassword(Models.ChangePassword changepw)
 {
     if (ModelState.IsValid)
     {
         if (changepw.Successful(changepw.OldPassword, changepw.NewPassword))
         {
             return(View("Successful"));
         }
         else
         {
             return(Content("Incorrect Old Password!"));
         }
     }
     return(View());
 }
示例#12
0
 public ActionResult ChangePassword(Models.ChangePassword model)
 {
     if (Session["LogonAdmin"] == null)
     {
         TempData["resultInfo"] = "Your session has expired. Please Login and Try Again!";
         return(RedirectToAction("Login", "Action"));
     }
     if (model.admin.Password == model.password)
     {
         var admin = context.Logins.FirstOrDefault(x => x.Username == logonUserName);
         if (admin != null)
         {
             if (admin.Password == model.currentPassword)
             {
                 admin.Password = model.admin.Password;
                 try
                 {
                     context.Entry <Database.Logins>(admin).State = System.Data.Entity.EntityState.Modified;
                     context.SaveChanges();
                     TempData["resultInfo"] = "Your Password has been changed successfully";
                 }
                 catch (Exception ex)
                 {
                     TempData["resultInfo"] = "Sorry, your password could not be changed!";
                 }
                 return(View(new Models.ChangePassword()));
             }
             else
             {
                 TempData["resultInfo"] = "Your current password is not correct";
                 return(View(new Models.ChangePassword()));
             }
         }
         else
         {
             TempData["resultInfo"] = "Your password could not be changed!";
             return(View(new Models.ChangePassword()));
         }
     }
     else
     {
         TempData["resultInfo"] = "Passwords do not match!";
         return(View(new Models.ChangePassword()));
     }
 }
示例#13
0
 public string SavePassword(Models.ChangePassword c)
 {
     try
     {
         var db = new TMRC_CSP.ViewModel.Context.ConnectionStringsContext();
         if (Login._r.Password == c.OldPassword) //Confirmation is it valid user
         {
             var res = db.Resellers.Where(m => m.Email == Login._r.Email).SingleOrDefault();
             res.Password         = c.NewPassword;
             res.Is1stTimePassChg = true;
             db.SaveChanges();
             ViewModel.Account.Login login = new ViewModel.Account.Login();
             login.SignOut();
             return("Successfully Password Changed.");
         }
         return("Unknown error ocuur, Please try again.");
     }
     catch (Exception ex)
     {
         return("Unknown error ocuur, Please try again.");
     }
 }
示例#14
0
        public async Task <IActionResult> ChangePassword(Models.ChangePassword args)
        {
            ViewData["Title"] = "Change Password";

            if (!ModelState.IsValid)
            {
                return(View());
            }

            var buser = new BLL.User(unitOfWork);

            var user = await buser.Get(new EF.User {
                UserId = Convert.ToInt16(((ClaimsIdentity)User.Identity).FindFirst(ClaimTypes.UserData).Value)
            });

            // Check password
            var salt = Core.Crypto.GenerateSalt();
            var enc  = Core.Crypto.Hash(args.NewPassword, salt);
            var pwd  = Core.Crypto.Hash(args.CurrentPassword, Convert.FromBase64String(user.PasswordSalt));

            if (pwd != user.PasswordHash)
            {
                ModelState.AddModelError(string.Empty, "Current password is invalid");
                return(View());
            }

            user.PasswordHash        = enc;
            user.PasswordSalt        = Convert.ToBase64String(salt);
            user.LastPasswordChanged = DateTime.Now;
            user.DateConfirmed       = DateTime.Now;
            user.ConfirmationCode    = null;
            user.ConfirmationExpiry  = null;
            user.DateInactive        = null;

            await buser.Edit(user);

            TempData["notice"] = "Succesfully changed password.";
            return(Redirect("~/Main"));
        }
示例#15
0
        public ActionResult ChangePassword(Models.ChangePassword changePasswordModel)
        {
            if (ModelState.IsValid)
            {
                Models.MyIdentityUser user = userManager.FindByName(HttpContext.User.Identity.Name);

                IdentityResult result = userManager.ChangePassword(user.Id, changePasswordModel.OldPassword, changePasswordModel.NewPassword);

                if (result.Succeeded)
                {
                    IAuthenticationManager authenticationManager = HttpContext.GetOwinContext().Authentication;
                    authenticationManager.SignOut();
                    return(RedirectToAction("Login", "Account"));
                }
                else
                {
                    ModelState.AddModelError("", "Error while changing the password");
                }
            }

            return(View(changePasswordModel));
        }
        public ActionResult ChangePassword()
        {
            var changePwdModel = new Models.ChangePassword();

            return(View(changePwdModel));
        }