Ejemplo n.º 1
0
        public ActionResult ResetPassword(ResetPasswordModel model)
        {
            EventLogHandler Logger = new EventLogHandler();

            var message = "";

            if (ModelState.IsValid)
            {
                List <CreateUser> validatePasswordCode;

                using (IDbConnection db = new SqlConnection(SqlAccess.GetConnectionString()))
                {
                    validatePasswordCode = db.Query <CreateUser>($"Select * from dbo.Usertable Where ResetPasswordCode = @ResetCode", new { ResetCode = model.ResetCode }).ToList();
                }

                if (validatePasswordCode.Count > 0)
                {
                    OldPasswordHandler PassHand = new OldPasswordHandler();
                    PassHand.AdjustOldPasswords(validatePasswordCode[0].Password, validatePasswordCode[0].ID);
                    using (IDbConnection db = new SqlConnection(SqlAccess.GetConnectionString()))
                    {
                        string sql = $"Update dbo.UserTable set Password = @Password, ResetPasswordCode = NULL where Username = @Username";
                        db.Execute(sql, new { Password = model.Password, Username = validatePasswordCode[0].Username });
                        message = "Password updated successfully.";
                        Logger.LogPasswordReset(validatePasswordCode[0].ID, validatePasswordCode[0].Username);
                        ViewBag.Message = message;
                    }
                }
            }


            return(View(model));
            //if (ModelState.IsValid)
            //{
            //    using (Database1Entities5 dc = new Database1Entities5())
            //    {
            //        var user = dc.CreateUsers.Where(a => a.ResetPasswordCode == model.ResetCode).FirstOrDefault();
            //        if (user != null)
            //        {
            //            OldPasswordHandler PassHand = new OldPasswordHandler();
            //            PassHand.AdjustOldPasswords(user.Password, user.ID);

            //            user.Password = model.Password;
            //            user.ResetPasswordCode = "";

            //            dc.SaveChanges();
            //            Logger.LogPasswordReset(user.ID, user.Username);
            //            Database1Entities6 db2 = new Database1Entities6();
            //            var events = db2.EventLogs.ToList();
            //            var message = "Password updated successfully.";
            //            ViewBag.Message = message;
            //        }
            //    }
            //}
            //return View(model);
        }
Ejemplo n.º 2
0
        public ActionResult ChangePassword(ChangePasswordModel model)
        {
            //have to add code to replace password still
            //use old passsword handler
            EventLogHandler Logger = new EventLogHandler();

            List <CreateUser> user;

            using (IDbConnection db = new SqlConnection(SqlAccess.GetConnectionString()))
            {
                var sessionUser = Session["Username"] as string;

                user = db.Query <CreateUser>("Select * from dbo.UserTable where Username = @Username;", new { Username = sessionUser }).ToList();
            }
            if (user.Count() > 0)
            {
                OldPasswordHandler PassHand = new OldPasswordHandler();
                PassHand.AdjustOldPasswords(model.CurrentPassword, user[0].ID);
                using (IDbConnection db = new SqlConnection(SqlAccess.GetConnectionString()))
                {
                    string sql = $"Update dbo.UserTable set Password = @Password where Username = @Username;";
                    db.Execute(sql, new { Password = user[0].Password, Username = user[0].Username });
                }
                Logger.LogPasswordChange();
                var message = "Password updated successfully.";
                ViewBag.Message = message;
            }
            // using (Database1Entities5 dc = new Database1Entities5())
            //{
            //    EventLogHandler Logger = new EventLogHandler();
            //    var sessionUser = Session["Username"] as string;

            //    var user = dc.CreateUsers.Where(a => a.Username == sessionUser).FirstOrDefault();
            //    if (user != null)
            //    {
            //        OldPasswordHandler PassHand = new OldPasswordHandler();
            //        PassHand.AdjustOldPasswords(model.CurrentPassword, user.ID);

            //        user.Password = model.NewPassword;
            //        dc.SaveChanges();

            //        Logger.LogPasswordChange();
            //        Database1Entities6 db2 = new Database1Entities6();
            //        var events = db2.EventLogs.ToList();
            //        var message = "Password updated successfully.";
            //        ViewBag.Message = message;
            //    }
            //}

            return(View(model));
        }