Пример #1
0
        public async Task <IActionResult> Create([Bind("CostumerId,Name,BirthDate,Location,Password,ConfirmPassword")] Customers customers)
        {
            byte[] salt = new byte[128 / 8];
            using (var rng = RandomNumberGenerator.Create())
            {
                rng.GetBytes(salt);
            }
            string hashed = Convert.ToBase64String(KeyDerivation.Pbkdf2(
                                                       password: customers.Password,
                                                       salt: salt,
                                                       prf: KeyDerivationPrf.HMACSHA1,
                                                       iterationCount: 10000,
                                                       numBytesRequested: 256 / 8));


            if (ModelState.IsValid)
            {
                var customer = new IdentityUser {
                    UserName = customers.Name
                };
                var result = await userManager.CreateAsync(customer, customers.Password);

                if (result.Succeeded)
                {
                    customers.Password        = hashed;
                    customers.ConfirmPassword = hashed;
                    _context.Add(customers);

                    await signInManager.SignInAsync(customer, isPersistent : false);

                    await _context.SaveChangesAsync();

                    return(RedirectToAction("Index", "Home"));
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError("", error.Description);
                }
            }
            return(View(customers));
        }
Пример #2
0
        public async Task <IActionResult> Create([Bind("CarRentID,ClientID,CarModel,StartDate,EndDate,City")] CarRent carRent)
        {
            if (ModelState.IsValid)
            {
                DateTime startDate = carRent.StartDate;
                DateTime endDate   = carRent.EndDate;
                int      clientID  = carRent.ClientID;

                if (startDate > endDate || clientID == 0)
                {
                    return(RedirectToAction(nameof(Create)));
                }
                else
                {
                    _context.Add(carRent);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            return(View(carRent));
        }