コード例 #1
0
        public void CheckHashTest()
        {
            Pbkdf2PasswordHasher hasher = new Pbkdf2PasswordHasher();

            var result = hasher.VerifyHashedPassword("vGawPyJwb3h4gpYiyxptJdUS31lLLiVhJk2yzlsskx0=:doTdEmoK8ACsuIrLrp4riGYCqi6DEn4CyitpOqoVrFA=", "abcd123");

            Assert.AreEqual(PasswordVerificationResult.Success, result);
        }
コード例 #2
0
        public void Pbkdf2()
        {
            var hasher         = new Pbkdf2PasswordHasher();
            var hashedPassword = hasher.HashPassword(TestPassword, new SecureRandomGenerator());

            Assert.IsNotNull(hashedPassword);
            var flag = hasher.VerifyHashedPassword(hashedPassword, TestPassword);

            Assert.IsTrue(flag);
        }
コード例 #3
0
        public async Task <UserDto> LogIn(CredentialsViewModel viewModel)
        {
            var user = _unitOfWork.Users.All(nameof(User.Entitlements), nameof(User.Memberships), nameof(User.Preferences))
                       .SingleOrDefault(u => u.Email == viewModel.Email) ?? throw new Exception(Constants.InvalidCredentialsExceptionMessage);

            var hasher = new Pbkdf2PasswordHasher();

            if (hasher.VerifyHashedPassword(user, user.Password, viewModel.Password) == PasswordVerificationResult.Failed)
            {
                throw new Exception(Constants.InvalidCredentialsExceptionMessage);
            }
            return(await _userToUserDtoConverter.Convert(user));
        }