public ActionResult ChangePassword(User usr)
        {
            var SessionVal = HttpContext.Session.GetString("EmailID");

            if (string.IsNullOrEmpty(SessionVal))
            {
                return(RedirectToAction("Login", "User"));
            }

            using (DNDAuthDBContext dc = new DNDAuthDBContext())
            {
                var RealUserData = dc.Users.Where(x => x.EmailID == SessionVal).FirstOrDefault();

                RealUserData.Password        = Crypto.Hash(usr.Password);
                RealUserData.ConfirmPassword = Crypto.Hash(usr.ConfirmPassword);

                dc.Users.Update(RealUserData);
                dc.SaveChanges();
            }

            return(View());
        }
        public ActionResult VerifyAccount(string id)
        {
            bool Status = false;

            using (DNDAuthDBContext dc = new DNDAuthDBContext())
            {
                //dc.Configuration.ValidateOnSaveEnabled = false; // This line I have added here to avoid
                // Confirm password does not match issue on save changes
                var v = dc.Users.Where(a => a.ActivationCode == new Guid(id)).FirstOrDefault();
                if (v != null)
                {
                    v.IsEmailVerified = true;
                    dc.SaveChanges();
                    Status = true;
                }
                else
                {
                    ViewBag.Message = "Invalid Request";
                }
            }
            ViewBag.Status = Status;
            return(View());
        }
        public ActionResult Registration(User user)
        {
            using (DNDAuthDBContext dc = new DNDAuthDBContext())
            {
                bool   Status  = false;
                string message = "";
                ViewBag.SecurityQuesID = LoadAllSecurityQuestions();
                //ViewBag.SecurityQuestionList = ToSelectList(SecurityQuestionList(), "SecurityQuesID", "SecurityQues");

                using (var transaction = dc.Database.BeginTransaction())
                {
                    try
                    {
                        //
                        // Model Validation
                        if (ModelState.IsValid)
                        {
                            #region //Email is already Exist
                            var isExist = IsEmailExist(user.EmailID);
                            if (isExist)
                            {
                                ModelState.AddModelError("EmailExist", "Email already exist");
                                return(View(user));
                            }
                            #endregion

                            #region Generate Activation Code
                            user.ActivationCode = Guid.NewGuid();
                            #endregion

                            #region  Password Hashing
                            user.Password        = Crypto.Hash(user.Password);
                            user.ConfirmPassword = Crypto.Hash(user.ConfirmPassword); //
                            #endregion
                            user.IsEmailVerified = false;

                            #region Save to Database

                            dc.Users.Add(user);
                            dc.SaveChanges();

                            //Send Email to User
                            SendVerificationLinkEmail(user.EmailID, user.ActivationCode.ToString());
                            message = "Registration successfully done. Account activation link " +
                                      " has been sent to your email id:" + user.EmailID;
                            Status = true;

                            transaction.Commit();

                            #endregion
                        }
                        else
                        {
                            message = "Invalid Request";
                        }

                        ViewBag.Message = message;
                        ViewBag.Status  = Status;
                        return(View(user));
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();

                        string Error = ex.Message.ToString();
                        ViewBag.Message = Error;
                        ViewBag.Status  = Status;

                        return(View(user));
                    }
                }
            }
        }