Ejemplo n.º 1
0
        public void VerifyHashedPassword_WithDefaultSettings_ExpectSuccess()
        {
            var password       = Guid.NewGuid().ToString();
            var hashedPassword = BCrypt.Net.BCrypt.HashPassword(password);

            var hasher = new BCryptPasswordHasher <string>();

            hasher.VerifyHashedPassword("", hashedPassword, password).Should().Be(PasswordVerificationResult.Success);
        }
Ejemplo n.º 2
0
        public void VerifyHashedPassword_WhenCorrectV10Password_ExpectSuccess()
        {
            const string password       = "******";
            const string hashedPassword = "******";

            var hasher = new BCryptPasswordHasher <string>();

            hasher.VerifyHashedPassword("", hashedPassword, password).Should().Be(PasswordVerificationResult.Success);
        }
Ejemplo n.º 3
0
        public void VerifyHashedPassword_WhenSuppliedPasswordDoesNotMatch_ExpectFailure()
        {
            var password       = Guid.NewGuid().ToString();
            var hashedPassword = BCrypt.Net.BCrypt.HashPassword(Guid.NewGuid().ToString());

            var hasher = new BCryptPasswordHasher <string>();

            hasher.VerifyHashedPassword("", hashedPassword, password).Should().Be(PasswordVerificationResult.Failed);
        }
Ejemplo n.º 4
0
        public void VerifyHashedPassword_WhenPasswordCreatedWithEnhancedEntropyButVerifiedWithout_ExpectFailure()
        {
            var options = new BCryptPasswordHasherOptions {
                EnhancedEntropy = true
            };
            var password       = Guid.NewGuid().ToString();
            var hashedPassword = BCrypt.Net.BCrypt.HashPassword(password, options.WorkFactor);

            var hasher = new BCryptPasswordHasher <string>(new OptionsWrapper <BCryptPasswordHasherOptions>(options));

            hasher.VerifyHashedPassword("", hashedPassword, password).Should().Be(PasswordVerificationResult.Failed);
        }
Ejemplo n.º 5
0
        public void VerifyHashedPassword_WithEnhancedEntropy_ExpectSuccess()
        {
            var options = new BCryptPasswordHasherOptions {
                EnhancedEntropy = true
            };
            var password       = Guid.NewGuid().ToString();
            var hashedPassword = BCrypt.Net.BCrypt.HashPassword(password, options.WorkFactor, true);

            var hasher = new BCryptPasswordHasher <string>(new OptionsWrapper <BCryptPasswordHasherOptions>(options));

            hasher.VerifyHashedPassword("", hashedPassword, password).Should().Be(PasswordVerificationResult.Success);
        }
Ejemplo n.º 6
0
        public User Authenticate(UserDto userDto)
        {
            var user = GetUserByUsername(userDto.Username);

            if (user == null)
            {
                return(null);
            }

            var verificationResult = _passwordHasher.VerifyHashedPassword(user, user.PasswordHash, userDto.Password);

            if (verificationResult == PasswordVerificationResult.Success)
            {
                return(user);
            }

            return(null);
        }