public ActionResult Create(UserViewModel model)
        {
            try
            {
                Logger.Debug("kjfkdjkfj");
                // TODO: Add insert logic here
                UserEntity userInfo = new UserEntity()
                {
                    UserName = model.UserName,
                    NormalizedUserName = model.UserName,
                    Password = model.UserPassword
                };

                if (ModelState.IsValid)
                {
                    _membershipService.CreateUser(new CreateUserParams(
                                     model.NormalizedUserName,
                                     model.UserName,
                                     model.UserPassword,
                                     model.Email));

                    return RedirectToAction("Index");
                }
                return View(model);
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, ex.Message);
                return View(model);
            }
        }
        public IUser CreateUser(CreateUserParams createUserParams)
        {
            UserEntity model = new UserEntity();

            model.NormalizedUserName = createUserParams.NormalizedUserName;
            model.UserName = createUserParams.Username;
            model.Email = createUserParams.Email;
            model.HashAlgorithm = "SHA1";
            SetPassword(model, createUserParams.Password);
            return _userRep.Add(model);
        }
Exemple #3
0
        public ActionResult Edit(UserViewModel userInfo)
        {
            UserEntity model = new UserEntity();
            UpdateModel(model);
            _membershipServiceInModule.Update(model);
            ViewData["aaaa"] = new List<SelectListItem>()
            {
                new SelectListItem(){ Text="ddd",Value="2" },
                new SelectListItem(){ Text="cc",Value="1" }
            };

            return View(userInfo);
        }
Exemple #4
0
 private void InitializeProducts()
 {
     // Create a list of products. 50% of them are in the Shoes category, 25% in the Electronics
     // category and 25% in the Food category.
     for (var i = 0; i < 527; i++)
     {
         var product = new UserEntity();
         product.NormalizedUserName = "******" + (i + 1);
         var categoryIndex = i % 4;
         if (categoryIndex > 2)
         {
             categoryIndex = categoryIndex - 3;
         }
         //product.Category = allCategories[categoryIndex];
         allUsers.Add(product);
     }
 }
        private void SetPasswordHashed(UserEntity model, string password)
        {
            var saltBytes = new byte[0x10];
            using (var random = new RNGCryptoServiceProvider())
            {
                random.GetBytes(saltBytes);
            }

            var passwordBytes = Encoding.Unicode.GetBytes(password);

            var combinedBytes = saltBytes.Concat(passwordBytes).ToArray();

            byte[] hashBytes;
            using (var hashAlgorithm = HashAlgorithm.Create(model.HashAlgorithm))
            {
                hashBytes = hashAlgorithm.ComputeHash(combinedBytes);
            }

            model.PasswordFormat = MembershipPasswordFormat.Hashed;
            model.Password = Convert.ToBase64String(hashBytes);
            model.PasswordSalt = Convert.ToBase64String(saltBytes);
        }
 private void SetPassword(UserEntity model, string password)
 {
     SetPasswordHashed(model, password);
 }