public async Task SeedUsers() { // If the db is not empty abort the seeding if (await _context.Users.AnyAsync()) { return; } var userData = System.IO.File.ReadAllText("Data/UserSeedData.json"); var users = JsonConvert.DeserializeObject <List <User> >(userData); // All the test user will use the password "password" (byte[] passwordHash, byte[] passwordSalt) = Helpers.HmacHelper.ComputeHashSalt("password"); foreach (var user in users) { user.PasswordHash = passwordHash; user.PasswordSalt = passwordSalt; user.Username = user.Username.ToLowerInvariant(); _context.Users.Add(user); } await _context.SaveChangesAsync(); }
public async Task <User> Register(User user, string password) { if (user == null) { return(null); } // The password must be a not empty string if (string.IsNullOrWhiteSpace(password)) { return(null); } (user.PasswordHash, user.PasswordSalt) = HmacHelper.ComputeHashSalt(password); await _context.Users.AddAsync(user); await _context.SaveChangesAsync(); return(user); }
public async Task <bool> SaveAll() { return(await _context.SaveChangesAsync() > 0); }