コード例 #1
0
        public void ValidatePassword_CorrectPassword_ShouldReturnTrue()
        {
            var  user   = PasswordHashService.HashPassword("Pa55word");
            bool result = PasswordHashService.ValidatePassword("Pa55word", user);

            Assert.IsTrue(result);
        }
コード例 #2
0
        public void ValidatePassword_WrongPassword_ShouldReturnFalse()
        {
            var  user   = PasswordHashService.HashPassword("Pa55word");
            bool result = PasswordHashService.ValidatePassword("Password", user);

            Assert.IsFalse(result);
        }
コード例 #3
0
        static void Main(string[] args)
        {
            var hasher = new PasswordHashService();

            Console.Write("Password : "******"Password Hash: {passwordHash}");
            Console.ReadLine();
        }
コード例 #4
0
        public void HashPassword_CorrectData_ShouldReturnHashedPassword()
        {
            string password   = "******";
            string hashedPass = String.Empty;
            string salt       = String.Empty;

            for (int i = 0; i < 50; i++)
            {
                var user          = PasswordHashService.HashPassword(password);
                var newHashedPass = user.PasswordHash;
                var newSalt       = user.Salt;
                Assert.That(hashedPass, Is.Not.EqualTo(newHashedPass));
                Assert.That(salt, Is.Not.EqualTo(newSalt));
                hashedPass = newHashedPass;
                salt       = newSalt;
            }
        }
コード例 #5
0
        public async Task <IActionResult> Register([FromBody] RegisterRequest request)
        {
            string hashedPassword = PasswordHashService.HashPassword(request.Password);
            var    user           = new User
            {
                Email    = request.Email,
                UserName = request.UserName,
                Password = hashedPassword
            };

            User registeredUser = await _userService.RegisterAsync(user);

            if (registeredUser != null)
            {
                ClaimsPrincipal claimsPrincipal = _userService.CreateClaimsPrinciple(user);
                await Request.HttpContext.SignInAsync("Cookies", claimsPrincipal);

                return(Ok(new { test = "test" }));
            }

            return(BadRequest());
        }