Exemplo n.º 1
0
        public void TestBCryptConfigurationConstructor512()
        {
            BCryptConfiguration configuration = new BCryptConfiguration(KeyDerivationPrf.HMACSHA512, 2);

            Assert.AreEqual(configuration.Prf, KeyDerivationPrf.HMACSHA512);
            Assert.AreEqual(configuration.IterationCount, 2);
        }
Exemplo n.º 2
0
        public void TestBCryptConfigurationDefault()
        {
            BCryptConfiguration configuration = new BCryptConfiguration();

            Assert.AreEqual(configuration.Prf, KeyDerivationPrf.HMACSHA512);
            Assert.AreEqual(configuration.IterationCount, 10000);
        }
Exemplo n.º 3
0
        public void TestBCryptConstructorReturnValueWithHMACSHA256()
        {
            string password = "******";
            BCryptConfiguration configuration = new BCryptConfiguration(KeyDerivationPrf.HMACSHA256);
            BCrypt      bCrypt      = new BCrypt(configuration);
            BCryptValue bCryptValue = bCrypt.Hash(password);

            Assert.IsTrue(bCrypt.Valid(password, bCryptValue));
        }
Exemplo n.º 4
0
        public void TestBCryptConstructorReturnValue()
        {
            string password = "******";
            BCryptConfiguration configuration = new BCryptConfiguration();
            BCrypt      bCrypt      = new BCrypt(configuration);
            BCryptValue bCryptValue = bCrypt.Hash(password);

            Assert.IsTrue(bCrypt.Valid(password, bCryptValue));
        }
Exemplo n.º 5
0
        public void TestBCryptConfigurationConstructor512SaltAndHashed()
        {
            BCryptConfiguration configuration = new BCryptConfiguration(KeyDerivationPrf.HMACSHA512, 2, 1, 1);

            Assert.AreEqual(configuration.Prf, KeyDerivationPrf.HMACSHA512);
            Assert.AreEqual(configuration.IterationCount, 2);
            Assert.AreEqual(configuration.SaltBytesLength, 1);
            Assert.AreEqual(configuration.NumBytesRequestedLength, 1);
        }
Exemplo n.º 6
0
        public void TestBCryptConstructorReturnValueWithHMACSHA512AndInterationCountDescribeValue()
        {
            string password = "******";
            BCryptConfiguration configuration = new BCryptConfiguration(KeyDerivationPrf.HMACSHA512, 2000);
            BCrypt      bCrypt      = new BCrypt(configuration);
            BCryptValue bCryptValue = bCrypt.Hash(password);

            Assert.IsTrue(bCrypt.Valid(password, bCryptValue.Salt, bCryptValue.Hashed));
        }
Exemplo n.º 7
0
        public void TestBCryptConstructorReturnValueWithHMACSHA512AndInterationCountDescribeValueSaltAndHashedLength()
        {
            const int           length        = 75;
            string              password      = "******";
            BCryptConfiguration configuration =
                new BCryptConfiguration(KeyDerivationPrf.HMACSHA512, 2000, length, length);
            BCrypt      bCrypt      = new BCrypt(configuration);
            BCryptValue bCryptValue = bCrypt.Hash(password);

            Assert.IsTrue(bCrypt.Valid(password, bCryptValue.Salt, bCryptValue.Hashed));
            Assert.AreEqual(2000, configuration.IterationCount);
            Assert.AreEqual(length, configuration.SaltBytesLength);
            Assert.AreEqual(length, configuration.NumBytesRequestedLength);
            Assert.AreEqual(bCryptValue.Salt.Length, 100);
            Assert.AreEqual(bCryptValue.Hashed.Length, 100);
        }
        /// <summary>
        /// static class GeneratePasswordExtensions
        /// </summary>
        /// <param name="services">IServiceCollection</param>
        /// <param name="configuration">BCryptConfiguration</param>
        /// <returns></returns>
        public static IServiceCollection AddGeneratePassword(
            this IServiceCollection services,
            Action <BCryptConfiguration> configuration = null)
        {
            BCryptConfiguration config = new BCryptConfiguration();

            if (configuration != null)
            {
                configuration?.Invoke(config);
            }

            services.AddScoped(_ => config);
            services.AddScoped <BCrypt>();

            return(services);
        }
Exemplo n.º 9
0
        public void TestBCryptConfigurationInstance()
        {
            BCryptConfiguration configuration = new BCryptConfiguration();

            Assert.IsInstanceOf <BCryptConfiguration>(configuration);
        }