コード例 #1
0
        public JsonResult Change(ChangePassModel model)
        {
            ChangePassResult result = new ChangePassResult();

            try
            {
                result.ChangeResult = _userService.ChangePassword(new UserService.ChangePassParams()
                {
                    UserId  = SessionUtils.LoginUserInfo.UserId,
                    NewPass = model.NewPassword,
                    OldPass = model.OldPassword
                });
            }
            catch (BusinessException exception)
            {
                _logger.DebugFormat("BusinessException: {0}-{1}", exception.ErrorCode, exception.Message);
                result.ErrorDescription = CommonUtils.GetEnumDescription(exception.ErrorCode);
            }
            catch (Exception exception)
            {
                _logger.Error(string.Format("Iternal error {0}", exception));
                result.ErrorDescription = CommonUtils.GetEnumDescription(ErrorCode.InternalErrorException);
            }

            return(Json(result));
        }
コード例 #2
0
        public IActionResult ChangePass([FromBody] ChangePassModel model)
        {
            var user = userService.Get(model.Email);

            if (user == null)
            {
                return(BadRequest());
            }
            try
            {
                userService.UpdateAuth(user, model.Password);
                return(Ok());
            }
            catch (AppException e)
            {
                return(BadRequest(new
                {
                    message = e.Message
                }));
            }
            catch
            {
                return(BadRequest(new
                {
                    message = "Произошла ошибка, попробуйте позже"
                }));
            }
        }
コード例 #3
0
        public static void ChangePassword(ChangePassModel _user, out string message)
        {
            try
            {
                message = "";

                using (var db = new eCardEntities())
                {
                    var user = db.UserAccount.FirstOrDefault(r => r.ID == UniversalService.CurrentUser.ID);

                    if (user != null)
                    {
                        if (user.Password == _user.CurrentPass)
                        {
                            user.Password = _user.NewPass;

                            db.Entry(user).State = System.Data.Entity.EntityState.Modified;

                            db.SaveChanges();
                        }
                        else
                        {
                            message = "Invalid Password";
                        }
                    }
                }
            }
            catch (Exception error)
            {
                message = error.Message;
            }
        }
コード例 #4
0
 public ActionResult Index(ChangePassModel model)
 {
     if (ModelState.IsValid)
     {
         if (new ChangePasswordDao().DoiMatKhau(model))
         {
             using (var query = new CoffeeHouseDbContext())
             {
                 user u = query.users.FirstOrDefault(x => x.email == model.email);
                 ViewData["id"] = u.id;
             }
             ViewBag.annoucement = "Đổi mật khẩu thành công";
             model = new ChangePassModel();
         }
         else
         {
             ViewBag.announcement = "Đổi mật khẩu không thành công";
             ModelState.AddModelError("", "Đổi mật khẩu không thành công");
             //ChangePassModel change = new ChangePassModel();
             return(View());
             //return Json(ViewData["id"]);
         }
     }
     //else
     //{
     //    return ModelState.Values.SelectMany(v => v.Errors);
     //}
     //return ModelState.IsValid;
     return(View());
 }
コード例 #5
0
        public ActionResult ChangePass()
        {
            var model = new ChangePassModel();

            try
            {
                var user = db.Users.Where(r => r.UserName.Equals(User.Identity.Name)).FirstOrDefault();
                if (user != null)
                {
                    model.UserId   = user.UserId;
                    model.UserName = user.UserName;
                }
                else
                {
                    return(RedirectToAction("SignOut"));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);

                EventWriter.WriteEventLog("AuthController - ChangePass: " + ex.ToString());
            }
            return(View(model));
        }
コード例 #6
0
        public ActionResult ChangePassword([Bind(Include = "OldPassword,NewPassword,ConfirmPassword")] ChangePassModel changePass)
        {
            if (string.IsNullOrEmpty(changePass.ConfirmPassword) || string.IsNullOrEmpty(changePass.NewPassword) || string.IsNullOrEmpty(changePass.OldPassword))
            {
                ViewBag.Msg = "أرجو ملىء البيانات اولا";
                return(View(changePass));
            }
            if (!changePass.ConfirmPassword.Equals(changePass.NewPassword))
            {
                ViewBag.Msg = "كلمة المرور الجديدة وتأكيدها غير متطابقان";
                return(View(changePass));
            }
            var rowExist = db.Users.Find(CurrentUser.UserID);

            if (rowExist != null)
            {
                if (!rowExist.Provider.Equals("LinkedBroker", StringComparison.OrdinalIgnoreCase))
                {
                    ViewBag.Msg = "لا يمكن تغيير كلمة المرور لمستخدم مسجل عبر مواقع التواصل الاجتماعى";
                    return(View(changePass));
                }
                var encOldPass = Encrypt.EncryptString(changePass.OldPassword);
                if (!encOldPass.Equals(rowExist.UserPassword))
                {
                    ViewBag.Msg = "كلمة المرور القديمة خاطئة أرجو المحاولة مرة أخرى";
                    return(View(changePass));
                }
                rowExist.UserPassword = Encrypt.EncryptString(changePass.NewPassword);
                db.SaveChanges();
                ViewBag.SuccessMsg = "تم حفظ البيانات بنجاح";
                return(View(changePass));
            }

            return(View(changePass));
        }
コード例 #7
0
 public ActionResult ChangePass(ChangePassModel model)
 {
     if (ModelState.IsValid)
     {
         var dao  = new UserDao();
         var pass = Encryptor.MD5Hash(model.Pass);
         if (dao.Login(model.Email, pass) == 3)
         {
             if (model.NewPass == model.ConfirmPass)
             {
                 if (dao.ChangePass(model.Email, Encryptor.MD5Hash(model.NewPass)))
                 {
                     TempData["Change"] = "";
                     return(Redirect("/dang-nhap"));
                 }
                 else
                 {
                     ModelState.AddModelError("", "Đổi mật khẩu không thành công!");
                 }
             }
             else
             {
                 ModelState.AddModelError("", "Xác nhận mật khẩu mới ko khớp!");
             }
         }
         else
         {
             ModelState.AddModelError("", "Sai tài khoản hoặc mật khẩu!");
         }
     }
     return(View());
 }
コード例 #8
0
 public ActionResult ChangePass(ChangePassModel cpm)
 {
     if (Session["Id"] != null)
     {
         int id = Convert.ToInt32(Session["Id"].ToString());
         using (projectEntities1 db = new projectEntities1())
         {
             MembersData usr = db.MembersDatas.Where(u => u.Id == id).FirstOrDefault();
             {
                 if (cpm.OldPassword == usr.Password)
                 {
                     usr.CPassword = cpm.CPassword;
                     usr.Password  = cpm.CPassword;
                     db.SaveChanges();
                     TempData["Success"] = "Password  Successfully Changed!";
                     return(RedirectToAction("Login", "Auth"));
                 }
                 else
                 {
                     TempData["Success"] = "OldPassword miss match";
                     return(RedirectToAction("Registration", "Auth"));
                 }
             }
         }
     }
     else
     {
         return(RedirectToAction("Forgot", "Auth"));
     }
 }
コード例 #9
0
        public ActionResult ChangePassword(ChangePassModel Model)
        {
            String Username = User.Identity.Name;
            User   user     = AccBO.GetUserByUsername(Username);

            if (ModelState.IsValid)
            {
                if (user.Password.Equals(Model.OldPassword))
                {
                    if (Model.OldPassword.Equals(Model.NewPassword))
                    {
                        ModelState.AddModelError("", "New password is the same as old password");
                    }
                    else
                    {
                        user.Password = Model.NewPassword;
                        AccBO.UpdateExist(user);
                        ViewBag.Message = "Password change successful.";
                        Model           = new ChangePassModel();
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Wrong old password");
                }
            }

            Model.InUser = user;
            return(View(Model));
        }
コード例 #10
0
        public JsonResult ChangePassword(ChangePassModel user)
        {
            string serverResponse = "";

            UserService.ChangePassword(user, out serverResponse);

            return(Json(serverResponse));
        }
コード例 #11
0
        public ActionResult ChangePassword()
        {
            String Username = User.Identity.Name;

            ChangePassModel Model = new ChangePassModel();

            Model.InUser = AccBO.GetUserByUsername(Username);
            return(View(Model));
        }
コード例 #12
0
        public bool ChangePass(ChangePassModel model)
        {
            var rs = new bool();

            if (model.userId == "246Vnpost" && model.oldPassword == "123456")
            {
                rs = true;
            }
            return(rs);
        }
コード例 #13
0
ファイル: AdminController.cs プロジェクト: dart647/Diploma
        public async Task <IActionResult> EditPasswordAsync(string id)
        {
            var user = await UserManager.FindByIdAsync(id);

            var model = new ChangePassModel
            {
                UserId = user.Id
            };

            return(View(model));
        }
コード例 #14
0
 //private CoffeeHouseDbContext context = new CoffeeHouseDbContext();
 public bool DoiMatKhau(ChangePassModel model)
 {
     using (var ctx = new CoffeeHouseDbContext())
     {
         string matkhau = Encrypt.MD5Hash(model.reNewPass);
         var    query   = (from u in ctx.users
                           join kh in ctx.khachhangs
                           on u.id equals kh.matk
                           where u.email == model.email && u.password == matkhau
                           select new
         {
             idUser = u.id,
             idKH = kh.makh,
             tenKH = kh.hoten,
             email = kh.email
         }).FirstOrDefault();
         if (query is null)
         {
             user u = ctx.users.FirstOrDefault(x => x.email == model.email);
             u.password = matkhau;
             ctx.users.AddOrUpdate(u);
             ctx.SaveChanges();
             return(true);
         }
         else
         {
             return(false);
         }
     }
     //    string matkhau = Encrypt.MD5Hash(model.reNewPass);
     //var query = (from u in context.users
     //             join kh in context.khachhangs
     //             on u.id equals kh.matk
     //             where u.email == model.email && u.password == matkhau
     //             select new
     //             {
     //                 idUser = u.id,
     //                 idKH = kh.makh,
     //                 tenKH = kh.hoten,
     //                 email = kh.email
     //             }).FirstOrDefault();
     //if (query != null)
     //{
     //        user u = context.users.FirstOrDefault(x => x.email == model.email);
     //        u.password = matkhau;
     //        context.users.AddOrUpdate(u);
     //        context.SaveChanges();
     //        return true;
     //}
     //else
     //{
     //    return false;
     //}
 }
コード例 #15
0
        public ActionResult ChangePass(ChangePassModel model)
        {
            var result = AccountBLL.Instance.ChangePassword(User.Identity.Name, model);

            if (result != null)
            {
                TempData["ChangePass"] = "******";
                return(RedirectToAction("Index", "ListModule"));
            }
            TempData["ChangePass"] = "******";
            return(RedirectToAction("Index", "ListModule"));
        }
コード例 #16
0
        public bool ChangePass(ChangePassModel value)
        {
            var passRecovery = LoadByGuid(value.RecoveryId);

            if (passRecovery.ValidTo >= DateTime.Now)
            {
                using (var userSvc = new UserSvc())
                {
                    var user = userSvc.Load(passRecovery.UserId);
                    user.Salt     = PiChallengeHelper.CreateSaltKey(10);
                    user.Password = PiChallengeHelper.EncryptText(value.Password.Trim(), user.Salt);
                    userSvc.Save(user);
                    return(true);
                }
            }
            return(false);
        }
コード例 #17
0
        public ActionResult ChangePass(ChangePassModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    // Get user
                    var user = db.Users.Where(r => r.UserId == model.UserId).FirstOrDefault();
                    if (user != null)
                    {
                        // Validate current password
                        if (SaltedHash.Verify(user.Salt, user.Password, model.PasswordCurrent))
                        {
                            // Change password
                            var sh = new SaltedHash(model.PasswordNew);
                            user.Salt     = sh.Salt;
                            user.Password = sh.Hash;
                            db.SaveChanges();
                            return(RedirectToAction("ChangePassSuccess", "Auth"));
                        }
                        else
                        {
                            ModelState.AddModelError("", "Mật khẩu hiện tại không đúng");
                        }
                    }
                    else
                    {
                        return(RedirectToAction("SignOut"));
                    }
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);

                EventWriter.WriteEventLog("AuthController - ChangePass: " + ex.ToString());
            }
            return(View(model));
        }
コード例 #18
0
ファイル: AdminController.cs プロジェクト: dart647/Diploma
        public async Task <IActionResult> EditPasswordAsync(ChangePassModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await UserManager.FindByIdAsync(model.UserId);

                var result = await UserManager.ChangePasswordAsync(user, model.CurrentPassword, model.NewPassword);

                if (!result.Succeeded)
                {
                    ModelState.AddModelError("", "Ошибка смены пароля");
                    return(View(model));
                }
            }
            else
            {
                ModelState.AddModelError("", "Ошибка валидации данных. Некоректные данные!");
                return(View(model));
            }

            return(RedirectToAction("Index"));
        }
コード例 #19
0
        public ActionResult ChangePassword(ChangePassModel model)
        {
            if (ModelState.IsValid)
            {
                // поиск пользователя в бд
                var user = UnitOfWork.Users.Users.FirstOrDefault(u => u.Password == model.OldPassword);

                if (user != null)
                {
                    if (model.OldPassword == user.Password)
                    {
                        user.Password = model.NewPassword;
                        UnitOfWork.Users.SaveUser(user);
                        UnitOfWork.SaveChanges();

                        return(RedirectToAction("UserInfo"));
                    }
                    ModelState.AddModelError("", "Введен неправильный текущий пароль");
                }
            }
            return(View());
        }
コード例 #20
0
        public HttpResponseMessage ChangePassword([FromBody] ChangePassModel value)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, value));
                }

                if (passRecoverySvc.ChangePass(value))
                {
                    return(Request.CreateResponse(HttpStatusCode.OK));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Algo falló al intentar cambiar tu contraseña. Intenta nuevamente más tarde"));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
コード例 #21
0
        public IActionResult ChangePass([FromBody] ChangePassModel new_pass)
        {
            if (new_pass == null)
            {
                return(BadRequest("Send credentials"));
            }

            if (new_pass.Password1.Length < 1 || new_pass.Password2.Length < 8 || new_pass.Password3.Length < 8)
            {
                return(BadRequest("Password is too short"));
            }
            if (new_pass.Password1.Equals(new_pass.Password2))
            {
                return(BadRequest("New password must be different"));
            }
            if (!new_pass.Password2.Equals(new_pass.Password3))
            {
                return(BadRequest("Confirm new password must be identical"));
            }

            string get_email;
            var    identity           = HttpContext.User.Identity as ClaimsIdentity;
            IEnumerable <Claim> claim = identity.Claims;
            var usernameClaim         = claim
                                        .Where(x => x.Type == ClaimTypes.Name)
                                        .FirstOrDefault();

            get_email = usernameClaim.Value;
            if (get_email == null || get_email.Length < 1)
            {
                return(Unauthorized("Invalid user"));
            }

            using (var _context = new AppDBContext())
            {
                try
                {
                    byte[] oldpass;
                    using (SHA256 mySHA256 = SHA256.Create())
                    {
                        oldpass = mySHA256.ComputeHash(Encoding.UTF8.GetBytes(new_pass.Password1));
                    }

                    var record = _context.Users.Where(users => (users.email == get_email && users.password == oldpass))
                                 .FirstOrDefault();
                    if (record == null)
                    {
                        return(BadRequest("User not found"));
                    }

                    using (SHA256 mySHA256 = SHA256.Create())
                    {
                        record.password = mySHA256.ComputeHash(Encoding.UTF8.GetBytes(new_pass.Password2));
                    }

                    _context.Users.Update(record);
                    _context.SaveChanges();
                }
                catch
                {
                    return(BadRequest("Invalid request"));
                }
            }

            return(Ok());
        }
コード例 #22
0
        public ActionResult ChangePassword(ChangePassModel model)
        {
            if (ModelState.IsValid)
            {
                User user;
                user = db.Users.FirstOrDefault(u => u.Email == User.Identity.Name);
                if (user != null)
                {
                    if (user.Email == User.Identity.Name)
                    {
                        using (MsSqlContext db = new MsSqlContext())
                        {
                            byte[] bytes = Encoding.Unicode.GetBytes(model.Password);
                            MD5CryptoServiceProvider CSP =
                                new MD5CryptoServiceProvider();

                            byte[] byteHash = CSP.ComputeHash(bytes);
                            model.Password = string.Empty;
                            foreach (byte b in byteHash)
                            {
                                model.Password += string.Format("{0:x2}", b);
                            }
                            if (model.Password == user.Password)
                            {
                                byte[] bytesnew = Encoding.Unicode.GetBytes(model.Password_new);
                                MD5CryptoServiceProvider CSPnew =
                                    new MD5CryptoServiceProvider();

                                byte[] byteHashnew = CSPnew.ComputeHash(bytesnew);
                                model.Password_new = string.Empty;
                                foreach (byte b in byteHashnew)
                                {
                                    model.Password_new += string.Format("{0:x2}", b);
                                }

                                byte[] bytesconf = Encoding.Unicode.GetBytes(model.ConfirmPassword);
                                MD5CryptoServiceProvider CSPconf =
                                    new MD5CryptoServiceProvider();

                                byte[] byteHashconf = CSP.ComputeHash(bytesconf);
                                model.ConfirmPassword = string.Empty;
                                foreach (byte b in byteHashconf)
                                {
                                    model.ConfirmPassword += string.Format("{0:x2}", b);
                                }
                                if (model.ConfirmPassword == model.Password_new)
                                {
                                    user.Password        = model.ConfirmPassword;
                                    db.Entry(user).State = EntityState.Modified;
                                    db.SaveChanges();
                                    return(RedirectToAction("Details"));
                                }
                            }
                            else
                            {
                                ModelState.AddModelError("Password", "Неверный пароль");
                            }
                        }
                    }
                    else
                    {
                        return(RedirectToAction("Details"));
                    }
                }
            }
            else
            {
                return(RedirectToAction("Login"));
            }
            return(View(model));
        }