public ActionResult Edit([Bind(Include = "Id,Username,Password,AcceptedEula")] User user) { if (ModelState.IsValid) { var plainPW = user.Password; //Encrypt PW var encryptedPW = General.AesEncrypt(plainPW, ConstantVars.IISAesSalt, ConstantVars.IISAesPassword); user.Password = encryptedPW; db.Entry(user).State = EntityState.Modified; db.SaveChanges(); List <UserClaim> userClaims = new List <UserClaim>(); UserClaim userSubjectClaim = new UserClaim() { ClaimType = "Subject", Value = user.Id.ToString(), Id = user.Id }; UserClaim userRoleClaim = new UserClaim() { ClaimType = "Role", Value = "User", Id = user.Id }; userClaims.Add(userSubjectClaim); userClaims.Add(userRoleClaim); db.UserClaims.AddRange(userClaims); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(user)); }
public ActionResult Create([Bind(Include = "Id,Username,Password,AcceptedEula")] User user) { if (ModelState.IsValid) { var plainPW = user.Password; //Encrypt PW var encryptedPW = General.AesEncrypt(plainPW, ConstantVars.IISAesSalt, ConstantVars.IISAesPassword); user.Password = encryptedPW; db.Users.Add(user); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(user)); }