public ActionResult PasswordSave([Bind(Include = "Password")] CustomAdminLogin userData)
        {
            AdminLogin user = db.AdminLogins.Where(x => x.ID == UserId).SingleOrDefault();

            if (user.Password == Crypto.Hash(userData.Password))
            {
                ViewBag.Samepassword = "******";
                return(View());
            }
            user.Password  = Crypto.Hash(userData.Password);
            user.IsBlocked = false;
            //db.Entry(userData).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
                Session["User"]      = user.UserName;
                countOfFailedAttempt = 0;
                SendConfirmationEmailPasswordChanged(user.Email);
                return(RedirectToAction("index", "Home"));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            return(View("CommonError"));
        }
        public ActionResult ChangePassword(CustomAdminLogin model, string oldpass)
        {
            AdminLogin user = db.AdminLogins.Where(x => x.ID == UserId).SingleOrDefault();

            if (user.Password == Crypto.Hash(oldpass))
            {
                string pattern = @"^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9]).{6,20}$";
                Match  result  = Regex.Match(model.Password, pattern);

                if (!result.Success)
                {
                    ViewBag.Samepassword = "******";
                    return(View());
                }

                else if (user.Password == Crypto.Hash(model.Password))
                {
                    ViewBag.Samepassword = "******";
                    return(View());
                }
                user.Password = Crypto.Hash(model.Password);
                try
                {
                    db.SaveChanges();
                    SendConfirmationEmailPasswordChanged(user.Email);
                    return(RedirectToAction("index", "Home"));
                }
                catch (DbEntityValidationException e)
                {
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                          eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                              ve.PropertyName, ve.ErrorMessage);
                        }
                    }
                    return(View());
                }
            }
            else
            {
                ViewBag.passwordFail = "Wrong Password";
                return(View());
            }
        }
        public ActionResult PasswordChangeAfterForgot(CustomAdminLogin userData)
        {
            ViewBag.InsertTokenMust = "ON";
            AdminLogin user = db.AdminLogins.Where(x => x.ID == UserId).SingleOrDefault();

            if (userData.Password == null)
            {
                ViewBag.Samepassword = "******";
                return(View());
            }

            string pattern = @"^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9]).{6,20}$";
            Match  result  = Regex.Match(userData.Password, pattern);

            if (!result.Success)
            {
                ViewBag.Samepassword = "******";
                return(View());
            }
            else if (user.Password == Crypto.Hash(userData.Password))
            {
                ViewBag.Samepassword = "******";
                return(View());
            }
            else if (userData.Password != userData.ConfirmPassword)
            {
                ViewBag.NotConfirmPassword = "******";
                return(View());
            }
            user.Password  = Crypto.Hash(userData.Password);
            user.IsBlocked = false;
            //db.Entry(userData).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
                Session["User"]      = user.UserName;
                countOfFailedAttempt = 0;
                SendConfirmationEmailPasswordChanged(user.Email);
                return(RedirectToAction("index", "Home"));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(View());
            }

            //ViewBag.InsertTokenMust = "ON";
            //AdminLogin user1 = db.AdminLogins.Where(x => x.ID == UserId).SingleOrDefault();
            //return View(user1);
            //AdminLogin user = db.AdminLogins.Where(x => x.ID == UserId).SingleOrDefault();

            //if (user.Password == Crypto.Hash(userData.Password))
            //{
            //    ViewBag.passwordSame = "This Password has been used in recent time.Choose another";
            //    return View();

            //}
            //user.Password = Crypto.Hash(userData.Password);
            //try
            //{
            //    db.SaveChanges();
            //    SendConfirmationEmailPasswordChanged(user.Email);
            //    return RedirectToAction("index", "Home");
            //}
            //catch (Exception)
            //{
            //    return View();
            //}
        }