示例#1
0
        public static async Task SeedUsers(MvcSoprofenContext context)
        {
            if (await context.Users.AnyAsync())
            {
                return;
            }

            var userData = await System.IO.File.ReadAllTextAsync("Data/UserSeedData.json");

            var users = JsonSerializer.Deserialize <List <AppUser> >(userData);

            foreach (var user in users)
            {
                using var hmac = new HMACSHA512();

                user.UserName     = user.UserName.ToLower();
                user.PasswordHash = hmac.ComputeHash(Encoding.UTF8.GetBytes("Password"));
                user.PasswordSalt = hmac.Key;

                context.Users.Add(user);
            }

            await context.SaveChangesAsync();
        }
示例#2
0
 public UserRepository(MvcSoprofenContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }