public async Task AddUserAsync(MyUser user, string password)
 {
     if (await UserExists(user))
     {
         throw new Exception(
             "A user with that Email address already exists");
     }
     var hasher = new MyPasswordHasher();
     user.PasswordHash = hasher.CreateHash(password).ToString();
     _db.Users.Add(user);
     await _db.SaveChangesAsync();
 }
        public async Task AddUserAsync(MyUser user, string password)
        {
            if (await UserExists(user))
            {
                throw new Exception(
                          "A user with that Email address already exists");
            }
            var hasher = new MyPasswordHasher();

            user.PasswordHash = hasher.CreateHash(password).ToString();
            _db.Users.Add(user);
            await _db.SaveChangesAsync();
        }
        protected async override void Seed(ApplicationDbContext context)
        {
            context.Companies.Add(new Company {
                Name = "Microsoft"
            });
            context.Companies.Add(new Company {
                Name = "Apple"
            });
            context.Companies.Add(new Company {
                Name = "Google"
            });
            context.SaveChanges();

            // Set up two initial users with different role claims:
            var dino = new MyUser {
                Email = "*****@*****.**"
            };
            var dino2 = new MyUser {
                Email = "*****@*****.**"
            };

            dino.Claims.Add(new MyUserClaim {
                ClaimType = ClaimTypes.Name, UserId = dino.Id, ClaimValue = dino.Email
            });
            dino.Claims.Add(new MyUserClaim {
                ClaimType = ClaimTypes.Role, UserId = dino.Id, ClaimValue = "Admin"
            });

            dino2.Claims.Add(new MyUserClaim {
                ClaimType = ClaimTypes.Name, UserId = dino2.Id, ClaimValue = dino2.Email
            });
            dino2.Claims.Add(new MyUserClaim {
                ClaimType = ClaimTypes.Role, UserId = dino2.Id, ClaimValue = "User"
            });

            var store = new MyUserStore(context);
            await store.AddUserAsync(dino, "DinosPassword");

            await store.AddUserAsync(dino2, "Dino2sPassword");
        }
        protected async override void Seed(ApplicationDbContext context)
        {
            context.Companies.Add(new Company {
                Name = "Microsoft"
            });
            context.Companies.Add(new Company {
                Name = "Apple"
            });
            context.Companies.Add(new Company {
                Name = "Google"
            });
            context.SaveChanges();

            // Set up two initial users with different role claims:
            var john = new MyUser {
                Email = "*****@*****.**"
            };
            var jimi = new MyUser {
                Email = "*****@*****.**"
            };

            john.Claims.Add(new MyUserClaim {
                ClaimType = ClaimTypes.Name, UserId = john.Id, ClaimValue = john.Email
            });
            john.Claims.Add(new MyUserClaim {
                ClaimType = ClaimTypes.Role, UserId = john.Id, ClaimValue = "Admin"
            });

            jimi.Claims.Add(new MyUserClaim {
                ClaimType = ClaimTypes.Name, UserId = jimi.Id, ClaimValue = jimi.Email
            });
            jimi.Claims.Add(new MyUserClaim {
                ClaimType = ClaimTypes.Role, UserId = john.Id, ClaimValue = "User"
            });

            var store = new MyUserStore(context);
            await store.AddUserAsync(john, "JohnsPassword");

            await store.AddUserAsync(jimi, "JimisPassword");
        }
 public async Task <bool> UserExists(MyUser user)
 {
     return(await _db.Users
            .AnyAsync(u => u.Id == user.Id || u.Email == user.Email));
 }
 public async Task<bool> UserExists(MyUser user)
 {
     return await _db.Users
         .AnyAsync(u => u.Id == user.Id || u.Email == user.Email);
 }
 public bool PasswordIsValid(MyUser user, string password)
 {
     var hasher = new MyPasswordHasher();
     var hash = hasher.CreateHash(password);
     return hash.Equals(user.PasswordHash);
 }