Example #1
0
        // ----------------------------------------------------------------------------------------------------------------------------

        private void CapitalizeRandomPassword(Password pPassword, int pMinimum, int pMaximum)
        {
            int capitalized = 0;

            do
            {
                int probability = 50;
                for (int index = 0; index < pPassword.ChunkCount; ++index)
                {
                    PasswordChunk chunk = pPassword.Chunks[index];
                    if (chunk.ChunkType == PasswordChunkType.Special)
                    {
                        continue;
                    }

                    if (_random.Next(100) < probability)
                    {
                        bool lastLetter;
                        if (chunk.CapitalizedFirst && chunk.CapitalizedLast)
                        {
                            continue;
                        }
                        if (chunk.CapitalizedFirst)
                        {
                            lastLetter = true;
                        }
                        else
                        {
                            lastLetter = !chunk.CapitalizedLast && Utils.Coin();
                        }

                        if (pPassword.CapitalizeChunk(index, lastLetter))
                        {
                            capitalized++;
                            probability -= 20;
                            if (probability <= 0)
                            {
                                break;
                            }
                            if (capitalized > pMaximum)
                            {
                                return;
                            }
                        }
                    }
                }
            } while (capitalized == 0);
        }