public async Task <IActionResult> Register(RegisterViewModel registerViewModel)
        {
            if (ModelState.IsValid)
            {
                try {
                    await using var transaction = dbContext.Database.BeginTransaction();
                    var salt = HashPassword.CreateSalt();
                    var hash = HashPassword.GenerateSaltedHash(Encoding.UTF8.GetBytes(registerViewModel.Password), salt);
                    var user = new User {
                        UserLogin = registerViewModel.Login,
                        UserSalt  = Convert.ToBase64String(salt),
                        UserHash  = Convert.ToBase64String(hash),
                        UserType  = "passenger"
                    };
                    await dbContext.User.AddAsync(user);

                    await dbContext.SaveChangesAsync();

                    var passenger = new Passenger {
                        IdUser                  = user.IdUser,
                        PassengerFullName       = registerViewModel.FullName,
                        PassengerBirthday       = registerViewModel.Birthday,
                        IdPassengerPassportType = registerViewModel.IdPassportType,
                        PassengerPassport       = registerViewModel.PassportData
                    };
                    await dbContext.Passenger.AddAsync(passenger);

                    await dbContext.SaveChangesAsync();

                    transaction.Commit();
                    await Authenticate(user);

                    return(RedirectToAction("Index", "Home"));
                } catch {
                    return(NotFound());
                }
            }
            ViewBag.PassportType = new SelectList(dbContext.PassportType.ToList(), "IdPassportType", "Passport");
            return(View(registerViewModel));
        }
        public async Task <IActionResult> Login(User user, string password)
        {
            ViewBag.CheckUserPassword = true;
            ViewBag.CheckUserLogin    = true;
            var item = dbContext.User.FirstOrDefault(x => x.UserLogin == user.UserLogin);

            if (item != null && !string.IsNullOrEmpty(password))
            {
                var salt       = Convert.FromBase64String(item.UserSalt);
                var saltedHash = HashPassword.GenerateSaltedHash(Encoding.UTF8.GetBytes(password), salt);
                var hash       = Convert.FromBase64String(item.UserHash);
                if (!HashPassword.CompareByteArrays(saltedHash, hash))
                {
                    ViewBag.CheckUserPassword = false;
                    return(View());
                }
                await Authenticate(item);

                return(item.UserType == "passenger" ? RedirectToAction("Index", "Home")
                    : RedirectToAction("Index", "Passenger"));
            }
            ViewBag.CheckUserLogin = false;
            return(View());
        }