Beispiel #1
0
        static int PasswordHashing(PBKDF2HashingService hashingService, Stopwatch stopwatch, int siteGuid, int batchSize)
        {
            var                  split1         = stopwatch.ElapsedMilliseconds;
            var                  siteUsers      = new SiteUserCollection();
            ISortExpression      sortExpression = new SortExpression(SiteUserFields.SiteUserGuid | SortOperator.Ascending);
            IPredicateExpression filter         = GetSelectionFilter(siteGuid);

            siteUsers.GetMulti(filter, null, batchSize); // We retreive a max of batchSize users
            var split2 = stopwatch.ElapsedMilliseconds;
            var amt    = siteUsers.GetDbCount(filter);
            var split3 = stopwatch.ElapsedMilliseconds;

            var loopsize = amt > batchSize ? batchSize : amt;

            Console.Write(", Fetching: " + loopsize + " users " + (split2 - split1) + "mS, ");

            var split4            = stopwatch.ElapsedMilliseconds;
            var clearTextPassword = "";
            var hashedPassword    = "";

            for (var j = 0; j < loopsize; j++)
            {
                SiteUserEntity user = siteUsers[j];
                clearTextPassword = user.SiteUserPassword;
                var before = stopwatch.ElapsedMilliseconds;
                hashedPassword = hashingService.CreateHash(clearTextPassword);
                var after = stopwatch.ElapsedMilliseconds;

                siteUsers[j].SiteUserPassword = hashedPassword;
                siteUsers[j].HashType         = (int)HashTypeEnum.PBKDF2;
            }
            var split5 = stopwatch.ElapsedMilliseconds;

            //            siteUsers.SaveMulti();
            Thread.Sleep(2000); // TODO enable line above an remove this one , simulate the Save time....

            var split6 = stopwatch.ElapsedMilliseconds;

            Console.Write("Hashing: " + (split5 - split4) + "mS, ");
            Console.Write(loopsize > 0 ? "(" + ((split5 - split4) / loopsize) + "mS/hashing), " : ", ");
            Console.WriteLine("Saving: " + (split6 - split5) + "mS");

            return(loopsize); // Hashed in this batch
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            MCB.MasterPiece.Data.DaoClasses.CommonDaoBase.ActualConnectionString = MCB.Configuration.ServerConfig.GetConnectionString(5);

            PBKDF2HashingService hashingService = new PBKDF2HashingService();

            Stopwatch stopwatch = new Stopwatch();

            Process.GetCurrentProcess().ProcessorAffinity = new IntPtr(2);             // Uses the second Core or Processor for the Test
            Process.GetCurrentProcess().PriorityClass     = ProcessPriorityClass.High; // Prevents "Normal" processes from interrupting Threads
            Thread.CurrentThread.Priority = ThreadPriority.Highest;                    // Prevents "Normal" Threads from interrupting this thread
            stopwatch.Reset();
            stopwatch.Start();
            Console.WriteLine("Password Hashing has started");

            int filterHusetSiteGuid         = 11961;
            AdminSitesCollection adminSites = GetAdminSites(-1);

            Console.WriteLine("Number of Admin Sites: " + adminSites.Count);

            IDictionary <int, string> excludeListDictionary = GetExcludeSitelist();

            Console.WriteLine("Excluding " + excludeListDictionary.Count + " sites");

            var numberOfAdminSites = adminSites.Count;

            numberOfAdminSites = 10;
            if (numberOfAdminSites > 0)
            {
                Console.WriteLine("Starting site loop: " + numberOfAdminSites + " sites");
                for (var i = 0; i < numberOfAdminSites; i++)
                {
                    int siteGuid = adminSites[i].SiteGuid;
                    if (excludeListDictionary.ContainsKey(siteGuid))
                    {
                        Console.WriteLine("-------------------------------------------------------");
                        Console.WriteLine(siteGuid + " -> NO HASHING, " + adminSites[i].AdminCompany.Name);
                    }
                    else
                    {
                        Console.WriteLine("-------------------------------------------------------");
                        Console.WriteLine(siteGuid + " -> Start Hashing, " + adminSites[i].AdminCompany.Name);
                        Console.Write("     AmountLeft: ");
                        var                  siteUsers      = new SiteUserCollection();
                        ISortExpression      sortExpression = new SortExpression(SiteUserFields.SiteUserGuid | SortOperator.Ascending);
                        IPredicateExpression filter         = GetSelectionFilter(siteGuid);
                        siteUsers.GetMulti(filter, null, null);
                        var amountLeft = siteUsers.GetDbCount(filter);
                        Console.Write(amountLeft);
                        if (amountLeft == 0)
                        {
                            Console.WriteLine(", Der var IKKE nongen at hashe");
                        }
                        else
                        {
                            while (amountLeft > 0)
                            {
                                amountLeft -= PasswordHashing(hashingService, stopwatch, siteGuid, 1); // hashing 1000 at the time
                                if (amountLeft == 0)
                                {
                                    Console.WriteLine("     AmountLeft: " + amountLeft + ". ");
                                }
                                else
                                {
                                    Console.Write("     AmountLeft: " + amountLeft);
                                }
                            }
                        }
                    }
                }
            }
            stopwatch.Stop();

            Console.WriteLine("Password Hashing has finished");
            Console.WriteLine("mS: " + stopwatch.ElapsedMilliseconds);
            Console.WriteLine("-------------------------------------------------------");
            Console.WriteLine("Press ENTER to close.");
            Console.ReadLine();
        }