Ejemplo n.º 1
0
        private static User CreateUser()
        {
            using (var ctx = _factory.CreateDbContext(new string[0]))
            {
                Console.WriteLine("Username (must be an Email): ");
                string username;
                do
                {
                    username = Console.ReadLine();
                } while (!username.IsValidEmail());

                Console.WriteLine("Password");
                var password = Console.ReadLine();

                var user = JwtAuthenticationService.CreateNewUser(username);
                JwtAuthenticationService.UpdatePassword(user, password);
                ctx.Users.Add(user);
                ctx.SaveChanges();

                var person = new RealPerson
                {
                    Firstname = "Mr.",
                    Lastname  = "Administrator",
                    UserId    = user.Id
                };

                ctx.RealPeople.Add(person);
                ctx.SaveChanges();

                return(user);
            }
        }
        public void UpdatePassword()
        {
            var user = new User();
            var pwd  = "NewPassword";

            pwd.HashPassword();

            JwtAuthenticationService.UpdatePassword(user, pwd);
            Assert.False(string.IsNullOrWhiteSpace(user.Password));
            Assert.False(string.IsNullOrWhiteSpace(user.Salt));
            Assert.True(string.IsNullOrWhiteSpace(user.ResetHash));
        }