public ActionResult Register(WholeUser user, string returnUrl) { ViewBag.roleID = new SelectList(db.Roles, "id", "name"); byte[] salt; new RNGCryptoServiceProvider().GetBytes(salt = new byte[16]); var pbkdf2 = new Rfc2898DeriveBytes(user.password, salt, 1000); byte[] hash = pbkdf2.GetBytes(20); byte[] hashBytes = new byte[36]; Array.Copy(salt, 0, hashBytes, 0, 16); Array.Copy(hash, 0, hashBytes, 16, 20); string savedPasswordHash = Convert.ToBase64String(hashBytes); var mongoUser = new MongoUser() { Email = user.email, Password = savedPasswordHash }; var client = new MongoClient("mongodb+srv://alfex971:[email protected]/test?retryWrites=true"); var mongoDatabase = client.GetDatabase("Accessories"); var collection = mongoDatabase.GetCollection <MongoUser>("User"); collection.InsertOne(mongoUser); var sqlUser = new User() { email = user.email, name = user.name, phone = user.phone, roleID = 1, }; var savedUser = usersDao.InsertUser(sqlUser); FormsAuthentication.SetAuthCookie(user.email, false); return(Redirect("/Home/Index")); }