示例#1
0
        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();
        }
示例#2
0
        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);
        }
示例#3
0
 public async Task <bool> SaveAll()
 {
     return(await _context.SaveChangesAsync() > 0);
 }