示例#1
0
 public bool Initialize(UserPasswordConfig config)
 {
     lock (this)
     {
         if (config != null && !this.initialized)
         {
             if (config.HistoryProvider != null)
             {
                 this.HistoryProvider = this.HistoryProvider = NameReflectionUtils.CreateInstance <UserPasswordHistoryProviderFactory>(config.HistoryProvider);
                 if (this.HistoryProvider != null)
                 {
                     if (this.HistoryProvider.Initialize())
                     {
                         this.MaxHistory = config.MaxHistory;
                         if (config.MinChar < config.MaxChar)
                         {
                             try
                             {
                                 this.Shaker = new SaltShaker((char)config.MinChar, (char)config.MaxChar, config.HashLength, SaltCreationModel.Repeatable, SaltEmbeddingModel.Randomized, -1);
                                 foreach (PasswordComplexityRule curRule in config.Rules)
                                 {
                                     if (curRule != null)
                                     {
                                         this.ComplexityChecker.Rules.Add(curRule);
                                     }
                                 }
                                 this.initialized = true;
                                 return(true);
                             }
                             catch
                             { }
                         }
                     }
                 }
             }
         }
     }
     return(false);
 }
示例#2
0
        static void ShakeAndBake(string password, int seed, int size)
        {
            SaltShaker shake;
            SaltPair   saltFirst;
            SaltPair   saltSecond;
            SaltPair   hashFirst;
            SaltPair   hashSecond;
            bool       match;
            string     salted;

            //Start with a pass
            shake = new SaltShaker(char.MinValue, char.MaxValue, size, SaltCreationModel.NonRepeatableStrong, SaltEmbeddingModel.Middle, seed);
            Console.WriteLine("==========================================");
            Console.WriteLine("Type A - nonRepeatable salts");
            Console.WriteLine("==========================================");
            Console.WriteLine("Password: "******"------------------------------------------");
            Console.WriteLine("Salt: " + saltFirst.Salt.GetHashCode());
            Console.WriteLine("Salted: " + saltFirst.SaltedPayload.GetHashCode());
            Console.WriteLine("------------------------------------------");

            shake      = new SaltShaker(char.MinValue, char.MaxValue, size, SaltCreationModel.NonRepeatableStrong, SaltEmbeddingModel.Middle, seed);
            saltSecond = shake.Salt(password);
            salted     = shake.Embed(password, saltFirst.Salt);
            Console.WriteLine("Salt: " + saltSecond.Salt.GetHashCode());
            Console.WriteLine("Salted: " + saltSecond.SaltedPayload.GetHashCode());
            Console.WriteLine("------------------------------------------");
            match = saltFirst.SaltedPayload.Equals(saltSecond.SaltedPayload);
            Console.WriteLine("Matches: " + match);
            match = saltFirst.SaltedPayload.Equals(salted);
            Console.WriteLine("MatchesB: " + match);
            salted = shake.Embed(password, saltSecond.Salt);
            match  = saltSecond.SaltedPayload.Equals(salted);
            Console.WriteLine("MatchesC: " + match);
            Console.WriteLine("==========================================");

            shake = new SaltShaker(char.MinValue, char.MaxValue, size, SaltCreationModel.Repeatable, SaltEmbeddingModel.Randomized, seed);
            Console.WriteLine("Type B");
            Console.WriteLine("==========================================");

            saltFirst = shake.Salt(password);
            hashFirst = PasswordUtils.Hash(shake, password);
            Console.WriteLine("------------------------------------------");
            Console.WriteLine("Salt: " + saltFirst.Salt.GetHashCode());
            Console.WriteLine("Salted: " + saltFirst.SaltedPayload.GetHashCode());
            Console.WriteLine("Hashed: " + hashFirst.SaltedPayload.GetHashCode());
            Console.WriteLine("UtilsMatch: " + PasswordUtils.Matches(shake, password, hashFirst.SaltedPayload));
            Console.WriteLine("------------------------------------------");

            shake      = new SaltShaker(char.MinValue, char.MaxValue, size, SaltCreationModel.Repeatable, SaltEmbeddingModel.Randomized, seed);
            saltSecond = shake.Salt(password);
            hashSecond = PasswordUtils.Hash(shake, password);
            Console.WriteLine("Salt: " + saltSecond.Salt.GetHashCode());
            Console.WriteLine("Salted: " + saltSecond.SaltedPayload.GetHashCode());
            Console.WriteLine("Hashed: " + hashFirst.SaltedPayload.GetHashCode());
            Console.WriteLine("UtilsMatch: " + PasswordUtils.Matches(shake, password, hashSecond.SaltedPayload));
            Console.WriteLine("------------------------------------------");
            match = saltFirst.SaltedPayload.Equals(saltSecond.SaltedPayload);
            Console.WriteLine("Matches (Pass): " + match);
            match = hashFirst.SaltedPayload.Equals(hashSecond.SaltedPayload);
            Console.WriteLine("Matches (Hash): " + match);
            Console.WriteLine("==========================================");
        }