public ActionResult Create(User user)
 {
     if (ModelState.IsValid)
     {
         user.Password = CodeFirstCrypto.HashPassword(user.Password);
         //CodeFirstSecurity.CreateAccount(user.Username, user.Password, user.Email, false);
         userRepository.InsertOrUpdate(user);
         userRepository.Save();
         Success("\u4fdd\u5b58\u6210\u529f\uff01");
         return RedirectToAction("Index");
     }
     else
     {
         Error("\u4fdd\u5b58\u5931\u8d25\uff0c\u8868\u5355\u4e2d\u5b58\u5728\u4e00\u4e9b\u9519\u8bef\uff01");
         return View();
     }
 }
 public ActionResult Edit(User user)
 {
     if (ModelState.IsValid)
     {
         userRepository.InsertOrUpdate(user, updateAttr);
         userRepository.Save();
         Success("\u4fee\u6539\u6210\u529f\uff01");
         return RedirectToAction("Index");
     }
     else
     {
         Error("\u4fee\u6539\u5931\u8d25\uff0c\u8868\u5355\u4e2d\u5b58\u5728\u4e00\u4e9b\u9519\u8bef\uff01");
         return View();
     }
 }
 public override string CreateAccount(string userName, string password, string email, bool requireConfirmationToken)
 {
     if (string.IsNullOrEmpty(password))
     {
         throw new MembershipCreateUserException(MembershipCreateStatus.InvalidPassword);
     }
     string hashedPassword = CodeFirstCrypto.HashPassword(password);
     if (hashedPassword.Length > 128)
     {
         throw new MembershipCreateUserException(MembershipCreateStatus.InvalidPassword);
     }
     if (string.IsNullOrEmpty(userName))
     {
         throw new MembershipCreateUserException(MembershipCreateStatus.InvalidUserName);
     }
     if (string.IsNullOrEmpty(email))
     {
         throw new MembershipCreateUserException(MembershipCreateStatus.InvalidEmail);
     }
     using (WebApp4Context context = new WebApp4Context())
     {
         dynamic user = context.User.FirstOrDefault(Usr => Usr.Username == userName);
         dynamic emailuser = context.User.FirstOrDefault(Usr => Usr.Email == email);
         if (user != null)
         {
             throw new MembershipCreateUserException(MembershipCreateStatus.DuplicateUserName);
         }
         if (emailuser != null)
         {
             throw new MembershipCreateUserException(MembershipCreateStatus.DuplicateEmail);
         }
         string token = null;
         if (requireConfirmationToken)
         {
             token = CodeFirstCrypto.GenerateToken();
         }
         int defaultNumPasswordFailures = 0;
         User NewUser = new User
         {
             //Id = Guid.NewGuid(),
             Username = userName,
             Password = hashedPassword,
             IsConfirmed = !requireConfirmationToken,
             Email = email,
             ConfirmationToken = token,
             PasswordChangedDate = DateTime.Now,
             PasswordFailuresSinceLastSuccess = defaultNumPasswordFailures,
             LastPasswordFailureDate = DateTime.Now
         };
         NewUser.GenerateNewIdentity();
         context.User.Add(NewUser);
         context.SaveChanges();
         return token;
     }
 }