コード例 #1
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         _provider?.Dispose();
     }
 }
コード例 #2
0
 /// <summary>
 /// Dispose.
 /// </summary>
 /// <param name="disposing">Dispose unmanaged resources.</param>
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         _rng?.Dispose();
     }
 }
コード例 #3
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         rngCryptoServiceProvider?.Dispose();
     }
 }
コード例 #4
0
ファイル: PasswordGenerator.cs プロジェクト: giorgizek/ZekV1
 protected virtual void Dispose(bool disposing)
 {
     if (!_disposed)
     {
         if (disposing)
         {
             _rngProvider?.Dispose();
         }
     }
     _disposed = true;
 }
コード例 #5
0
        private bool disposedValue = false; // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    provider?.Dispose();
                }

                disposedValue = true;
            }
        }
コード例 #6
0
ファイル: RNGRandom.cs プロジェクト: ryans610/Lahkesis
        /// <summary>
        ///
        /// </summary>
        /// <param name="disposing"></param>
#endif
        protected virtual void Dispose(
            bool disposing)
        {
            if (_disposed)
            {
                return;
            }
            if (!ReferenceEquals(_rngProvider, s_defaultRNGProvider))
            {
                //do not dispose default rng provider
                _rngProvider?.Dispose();
            }
            _rngProvider = null;
            _disposed    = true;
        }
コード例 #7
0
        /// <summary>
        /// Protected implementation of Dispose pattern.
        /// </summary>
        /// <param name="disposing"> </param>
        protected virtual void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (disposing)
            {
                // Dispose managed state (managed objects).
                csp?.Dispose();
            }

            _disposed = true;
        }
コード例 #8
0
ファイル: DiceExpression.cs プロジェクト: Th3-M4jor/BnBBot
        private bool disposedValue = false; // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    r?.Dispose();
                    //devRand?.Dispose();
                    // TODO: dispose managed state (managed objects).
                }
                //freeRand(randPtr);
                // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below.
                // TODO: set large fields to null.

                disposedValue = true;
            }
        }
コード例 #9
0
 protected virtual void Dispose(bool Disposing)
 {
     if (_disposed)
     {
         return;
     }
     if (Disposing)
     {
         // Dispose managed objects.
         _buffer = null;
         _random = null;
     }
     // Dispose unmanaged objects.
     _random?.Dispose();
     _random = null;
     Cipher?.Dispose();
     Cipher    = null;
     _disposed = true;
 }
コード例 #10
0
ファイル: pwgen.cs プロジェクト: andreabenetton/Pass4Win
        /// <summary>
        /// Generates a random password.
        /// </summary>
        /// <param name="minLength">
        /// Minimum password length.
        /// </param>
        /// <param name="maxLength">
        /// Maximum password length.
        /// </param>
        /// <returns>
        /// Randomly generated password.
        /// </returns>
        /// <remarks>
        /// The length of the generated password will be determined at
        /// random and it will fall with the range determined by the
        /// function parameters.
        /// </remarks>
        public static string Generate(int minLength, int maxLength)
        {
            // Make sure that input parameters are valid.
            if (minLength <= 0 || maxLength <= 0 || minLength > maxLength)
            {
                return(null);
            }

            // Create a local array containing supported password characters
            // grouped by types. You can remove character groups from this
            // array, but doing so will weaken the password strength.
            char[][] charGroups = new char[][]
            {
                passwordCharsLcase.ToCharArray(),
                     passwordCharsUcase.ToCharArray(),
                     passwordCharsNumeric.ToCharArray(),
                     passwordCharsSpecial.ToCharArray()
            };

            // Use this array to track the number of unused characters in each
            // character group.
            int[] charsLeftInGroup = new int[charGroups.Length];

            // Initially, all characters in each group are not used.
            for (int i = 0; i < charsLeftInGroup.Length; i++)
            {
                charsLeftInGroup[i] = charGroups[i].Length;
            }

            // Use this array to track (iterate through) unused character groups.
            int[] leftGroupsOrder = new int[charGroups.Length];

            // Initially, all character groups are not used.
            for (int i = 0; i < leftGroupsOrder.Length; i++)
            {
                leftGroupsOrder[i] = i;
            }

            // Use a 4-byte array to fill it with random bytes and convert it then
            // to an integer value.
            byte[] randomBytes = new byte[4];

            // Generate 4 random bytes.
            RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();

            rng.GetBytes(randomBytes);

            // Convert 4 bytes into a 32-bit integer value.
            int seed = BitConverter.ToInt32(randomBytes, 0);

            // Now, this is real randomization.
            Random random = new Random(seed);

            // This array will hold password characters.

            // Allocate appropriate memory for the password.
            var password = minLength < maxLength
                ? new char[random.Next(minLength, maxLength + 1)]
                : new char[minLength];

            // Index of the last non-processed group.
            int lastLeftGroupsOrderIdx = leftGroupsOrder.Length - 1;

            // Generate password characters one at a time.
            for (int i = 0; i < password.Length; i++)
            {
                // If only one character group remained unprocessed, process it;
                // otherwise, pick a random character group from the unprocessed
                // group list. To allow a special character to appear in the
                // first position, increment the second parameter of the Next
                // function call by one, i.e. lastLeftGroupsOrderIdx + 1.
                int nextLeftGroupsOrderIdx;
                if (lastLeftGroupsOrderIdx == 0)
                {
                    nextLeftGroupsOrderIdx = 0;
                }
                else
                {
                    nextLeftGroupsOrderIdx = random.Next(0, lastLeftGroupsOrderIdx);
                }

                // Get the actual index of the character group, from which we will
                // pick the next character.
                var nextGroupIdx = leftGroupsOrder[nextLeftGroupsOrderIdx];

                // Get the index of the last unprocessed characters in this group.
                var lastCharIdx = charsLeftInGroup[nextGroupIdx] - 1;

                // If only one unprocessed character is left, pick it; otherwise,
                // get a random character from the unused character list.
                var nextCharIdx = lastCharIdx == 0 ? 0 : random.Next(0, lastCharIdx + 1);

                // Add this character to the password.
                password[i] = charGroups[nextGroupIdx][nextCharIdx];

                // If we processed the last character in this group, start over.
                if (lastCharIdx == 0)
                {
                    charsLeftInGroup[nextGroupIdx] = charGroups[nextGroupIdx].Length;
                }
                // There are more unprocessed characters left.
                else
                {
                    // Swap processed character with the last unprocessed character
                    // so that we don't pick it until we process all characters in
                    // this group.
                    if (lastCharIdx != nextCharIdx)
                    {
                        char temp = charGroups[nextGroupIdx][lastCharIdx];
                        charGroups[nextGroupIdx][lastCharIdx] =
                            charGroups[nextGroupIdx][nextCharIdx];
                        charGroups[nextGroupIdx][nextCharIdx] = temp;
                    }

                    // Decrement the number of unprocessed characters in
                    // this group.
                    charsLeftInGroup[nextGroupIdx]--;
                }

                // If we processed the last group, start all over.
                if (lastLeftGroupsOrderIdx == 0)
                {
                    lastLeftGroupsOrderIdx = leftGroupsOrder.Length - 1;
                }

                // There are more unprocessed groups left.
                else
                {
                    // Swap processed group with the last unprocessed group
                    // so that we don't pick it until we process all groups.
                    if (lastLeftGroupsOrderIdx != nextLeftGroupsOrderIdx)
                    {
                        int temp = leftGroupsOrder[lastLeftGroupsOrderIdx];
                        leftGroupsOrder[lastLeftGroupsOrderIdx] =
                            leftGroupsOrder[nextLeftGroupsOrderIdx];
                        leftGroupsOrder[nextLeftGroupsOrderIdx] = temp;
                    }

                    // Decrement the number of unprocessed groups.
                    lastLeftGroupsOrderIdx--;
                }
            }

            // Convert password characters into a string and return the result.
            rng.Dispose();
            return(new string(password));
        }
コード例 #11
0
 public void Dispose() => crypto?.Dispose();
コード例 #12
0
 public void Dispose()
 {
     _byteRandomiser.Dispose();
 }
コード例 #13
0
 public void Dispose()
 {
     _rngProvider?.Dispose();
 }
コード例 #14
0
 public void Dispose()
 {
     random.Dispose();
 }
コード例 #15
0
        private void SaveSettings()
        {
            if (checkBoxChangeStaticInfo.Checked != Settings.Default.ChangeStaticInfo)
            {
                EntryOrGuidAndSourceType originalEntryOrGuidAndSourceType = ((MainForm)Owner).userControl.originalEntryOrGuidAndSourceType;
                ((MainForm)Owner).userControl.textBoxEntryOrGuid.Text          = originalEntryOrGuidAndSourceType.entryOrGuid.ToString();
                ((MainForm)Owner).userControl.comboBoxSourceType.SelectedIndex = ((MainForm)Owner).userControl.GetIndexBySourceType(originalEntryOrGuidAndSourceType.sourceType);
            }

            bool showTooltipsStaticly = Settings.Default.ShowTooltipsStaticly;
            bool generateComments     = Settings.Default.GenerateComments;
            bool phaseHighlighting    = false;// Settings.Default.PhaseHighlighting;

            RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();

            byte[] buffer = new byte[1024];

            rng.GetBytes(buffer);
            string salt = BitConverter.ToString(buffer);

            rng.Dispose();
            string decryptedPassword = textBoxPassword.Text;

            SAI_Editor_Manager.Instance.connString          = new MySqlConnectionStringBuilder();
            SAI_Editor_Manager.Instance.connString.Server   = textBoxHost.Text;
            SAI_Editor_Manager.Instance.connString.UserID   = textBoxUsername.Text;
            SAI_Editor_Manager.Instance.connString.Port     = CustomConverter.ToUInt32(textBoxPort.Text);
            SAI_Editor_Manager.Instance.connString.Database = textBoxWorldDatabase.Text;

            if (textBoxPassword.Text.Length > 0)
            {
                SAI_Editor_Manager.Instance.connString.Password = textBoxPassword.Text;
            }

            Settings.Default.UseWorldDatabase = radioButtonConnectToMySql.Checked;
            Settings.Default.Save();

            bool newConnectionSuccesfull = false;

            if (radioButtonConnectToMySql.Checked)
            {
                newConnectionSuccesfull = SAI_Editor_Manager.Instance.worldDatabase.CanConnectToDatabase(SAI_Editor_Manager.Instance.connString, false);
            }

            //! We also save the settings if no connection was made. It's possible the user unchecked
            //! the radioboxes, changed some settings and then set it back to no DB connection.
            if (newConnectionSuccesfull || !radioButtonConnectToMySql.Checked)
            {
                Settings.Default.Entropy     = salt;
                Settings.Default.Host        = textBoxHost.Text;
                Settings.Default.User        = textBoxUsername.Text;
                Settings.Default.Password    = textBoxPassword.Text.Length == 0 ? String.Empty : textBoxPassword.Text.ToSecureString().EncryptString(Encoding.Unicode.GetBytes(salt));
                Settings.Default.Database    = textBoxWorldDatabase.Text;
                Settings.Default.Port        = textBoxPort.Text.Length > 0 ? CustomConverter.ToUInt32(textBoxPort.Text) : 0;
                Settings.Default.AutoConnect = checkBoxAutoConnect.Checked;

                if (radioButtonConnectToMySql.Checked)
                {
                    SAI_Editor_Manager.Instance.ResetDatabases();
                }
            }

            Settings.Default.InstantExpand          = checkBoxInstantExpand.Checked;
            Settings.Default.PromptToQuit           = checkBoxPromptToQuit.Checked;
            Settings.Default.HidePass               = checkBoxHidePass.Checked;
            Settings.Default.AnimationSpeed         = CustomConverter.ToInt32(textBoxAnimationSpeed.Text);
            Settings.Default.PromptExecuteQuery     = checkBoxPromptExecuteQuery.Checked;
            Settings.Default.ChangeStaticInfo       = checkBoxChangeStaticInfo.Checked;
            Settings.Default.ShowTooltipsStaticly   = checkBoxShowTooltipsStaticly.Checked;
            Settings.Default.GenerateComments       = checkBoxAutoGenerateComments.Checked;
            Settings.Default.CreateRevertQuery      = checkBoxCreateRevertQuery.Checked;
            Settings.Default.PhaseHighlighting      = false;// checkBoxPhaseHighlighting.Checked;
            Settings.Default.DuplicatePrimaryFields = checkBoxDuplicatePrimaryFields.Checked;
            Settings.Default.WowExpansionIndex      = (uint)comboBoxWowExpansion.SelectedIndex;
            SAI_Editor_Manager.Instance.Expansion   = (WowExpansion)Settings.Default.WowExpansionIndex;
            Settings.Default.Save();

            if (newConnectionSuccesfull)
            {
                ((MainForm)Owner).checkBoxAutoConnect.Checked  = checkBoxAutoConnect.Checked;
                ((MainForm)Owner).textBoxHost.Text             = textBoxHost.Text;
                ((MainForm)Owner).textBoxUsername.Text         = textBoxUsername.Text;
                ((MainForm)Owner).textBoxPassword.Text         = decryptedPassword;
                ((MainForm)Owner).textBoxWorldDatabase.Text    = textBoxWorldDatabase.Text;
                ((MainForm)Owner).checkBoxAutoConnect.Checked  = checkBoxAutoConnect.Checked;
                ((MainForm)Owner).expandAndContractSpeed       = CustomConverter.ToInt32(textBoxAnimationSpeed.Text);
                ((MainForm)Owner).textBoxPassword.PasswordChar = Convert.ToChar(checkBoxHidePass.Checked ? '●' : '\0');
            }
            else if (radioButtonConnectToMySql.Checked) //! Don't report this if there is no connection to be made anyway
            {
                MessageBox.Show("The database settings were not saved because no connection could be established. All other changed settings were saved.", "Something went wrong!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            if (checkBoxAutoGenerateComments.Checked != generateComments && checkBoxAutoGenerateComments.Checked)
            {
                ((MainForm)Owner).userControl.GenerateCommentsForAllItems();
            }

            if (checkBoxShowTooltipsStaticly.Checked != showTooltipsStaticly)
            {
                ((MainForm)Owner).userControl.ExpandOrContractToShowStaticTooltips(!checkBoxShowTooltipsStaticly.Checked);
            }

            if (checkBoxPhaseHighlighting.Checked != phaseHighlighting)
            {
                ((MainForm)Owner).userControl.ListViewList.Apply(true);
                ((MainForm)Owner).userControl.checkBoxUsePhaseColors.Checked = checkBoxPhaseHighlighting.Checked;
            }

            ((MainForm)Owner).HandleUseWorldDatabaseSettingChanged();
        }
コード例 #16
0
        public static string ComputeHash(string plainText, Supported_HA hash, byte[] salt)
        {
            int minSaltLength = 4;
            int maxSaltLength = 16;

            byte[] SaltBytes = null;

            if (salt != null)
            {
                SaltBytes = salt;
            }
            else
            {
                Random r          = new Random();
                int    SaltLength = r.Next(minSaltLength, maxSaltLength);
                SaltBytes = new byte[SaltLength];
                RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
                rng.GetNonZeroBytes(SaltBytes);
                rng.Dispose();
            }

            byte[] plainData        = ASCIIEncoding.UTF8.GetBytes(plainText);
            byte[] plainDataAndSalt = new byte[plainData.Length + SaltBytes.Length];

            for (int x = 0; x < plainData.Length; x++)
            {
                plainDataAndSalt[x] = plainData[x];
            }
            for (int n = 0; n < SaltBytes.Length; n++)
            {
                plainDataAndSalt[plainData.Length + n] = SaltBytes[n];
            }

            byte[] hashValue = null;

            switch (hash)
            {
            case Supported_HA.SHA256:
                SHA256Managed sha256 = new SHA256Managed();
                hashValue = sha256.ComputeHash(plainDataAndSalt);
                sha256.Dispose();
                break;

            case Supported_HA.SHA384:
                SHA384Managed sha384 = new SHA384Managed();
                hashValue = sha384.ComputeHash(plainDataAndSalt);
                sha384.Dispose();
                break;

            case Supported_HA.SHA512:
                SHA512Managed sha512 = new SHA512Managed();
                hashValue = sha512.ComputeHash(plainDataAndSalt);
                sha512.Dispose();
                break;
            }

            byte[] result = new byte[hashValue.Length + SaltBytes.Length];

            for (int i = 0; i < hashValue.Length; i++)
            {
                result[i] = hashValue[i];
            }
            for (int j = 0; j < SaltBytes.Length; j++)
            {
                result[hashValue.Length + j] = SaltBytes[j];
            }

            return(Convert.ToBase64String(result));
        }
コード例 #17
0
 public void Dispose()
 {
     m_Provider.Dispose();
     m_Provider = null;
 }
コード例 #18
0
 protected virtual void Dispose(bool dispose)
 {
     crypto.Dispose();
     hash.Dispose();
 }
コード例 #19
0
ファイル: Game1.cs プロジェクト: cwl157/mytetrisclones
 /// <summary>
 /// UnloadContent will be called once per game and is the place to unload
 /// game-specific content.
 /// </summary>
 protected override void UnloadContent()
 {
     RandomNumberProvider.Dispose();
 }
コード例 #20
0
        public static string ComputeHash(string plainText, string hash, byte[] salt)
        {
            int minSaltLength = 4, maxSaltLength = 16;

            byte[] saltBytes = null;
            if (salt != null)
            {
                saltBytes = salt;
            }
            else
            {
                Random r          = new Random();
                int    SaltLength = r.Next(minSaltLength, maxSaltLength);
                saltBytes = new byte[SaltLength];
                RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
                rng.GetNonZeroBytes(saltBytes);
                rng.Dispose();
            }

            byte[] plainData         = ASCIIEncoding.UTF8.GetBytes(plainText);
            byte[] plainDataWithSalt = new byte[plainData.Length + saltBytes.Length];

            for (int x = 0; x < plainData.Length; x++)
            {
                plainDataWithSalt[x] = plainData[x];
            }
            for (int n = 0; n < saltBytes.Length; n++)
            {
                plainDataWithSalt[plainData.Length + n] = saltBytes[n];
            }

            byte[] hashValue = null;

            switch (hash)
            {
            case "SHA256":
                SHA256Managed sha = new SHA256Managed();
                hashValue = sha.ComputeHash(plainDataWithSalt);
                sha.Dispose();
                break;

            case "SHA384":
                SHA384Managed sha1 = new SHA384Managed();
                hashValue = sha1.ComputeHash(plainDataWithSalt);
                sha1.Dispose();
                break;

            case "SHA512":
                SHA512Managed sha2 = new SHA512Managed();
                hashValue = sha2.ComputeHash(plainDataWithSalt);
                sha2.Dispose();
                break;
            }

            byte[] result = new byte[hashValue.Length + saltBytes.Length];
            for (int x = 0; x < hashValue.Length; x++)
            {
                result[x] = hashValue[x];
            }
            for (int n = 0; n < saltBytes.Length; n++)
            {
                result[hashValue.Length + n] = saltBytes[n];
            }

            return(Convert.ToBase64String(result));
        }
コード例 #21
0
 public static void Dispose()
 {
     RngCsp.Dispose();
 }
コード例 #22
0
 /// <inheritdoc />
 public void Dispose()
 {
     _randomNumberGenerator.Dispose();
 }
コード例 #23
0
ファイル: PasswordGenerator.cs プロジェクト: DCNick3/PassGen
 public void Dispose()
 {
     _rng?.Dispose();
 }
コード例 #24
0
ファイル: Program.cs プロジェクト: notflan/etgui
 public void Dispose()
 {
     aes.Dispose();
     pf.Dispose();
     rng.Dispose();
 }
コード例 #25
0
 public void Dispose()
 {
     _cryptoServiceProvider?.Dispose();
 }
コード例 #26
0
        public void TearDown()
        {
#if !NETFX_3_5
            _rng.Dispose();
#endif
        }
コード例 #27
0
        public static bool SingleSignon(string userID)
        {
            Staff  thisUser    = null;
            string newPassword = "";

            try
            {
                // Log in as the administration user to find the user
                ProjectTileSqlDatabase defaultPtDb = SqlServerConnection.DefaultPtDbConnection();
                using (defaultPtDb)
                {
                    thisUser = defaultPtDb.Staff.FirstOrDefault(s => s.UserID == userID);
                }
                if (thisUser == null)
                {
                    MessageFunctions.InvalidMessage("No matching user found with UserID " + userID + ".", "Invalid UserID");
                    return(false);
                }
                else if (thisUser.SingleSignon && domainUser == thisUser.OSUser)
                {
                    char[] validChars = Enumerable.Range('A', 26)
                                        .Concat(Enumerable.Range('a', 26))
                                        .Concat(Enumerable.Range('0', 10))
                                        .Select(i => (char)i)
                                        .ToArray();

                    byte[] randomNumber             = new byte[64 + 1];
                    RNGCryptoServiceProvider crypto = new RNGCryptoServiceProvider();
                    using (crypto)
                    {
                        crypto.GetBytes(randomNumber);
                        int length = 32 + (int)(32 * (randomNumber[0] / (double)byte.MaxValue));
                        newPassword = new string(randomNumber
                                                 .Skip(1)
                                                 .Take(length)
                                                 .Select(b => (int)((validChars.Length - 1) * (b / (double)byte.MaxValue)))
                                                 .Select(i => validChars[i])
                                                 .ToArray()
                                                 );
                        newPassword = newPassword.Substring(0, Math.Min(newPassword.Length, 20));
                        crypto.Dispose();
                    }
                    AttemptLogin(userID, newPassword); // AttemptLogin will now handle the password change if needed
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (SqlException sqlException)
            {
                MessageFunctions.Error("Error accessing the database", sqlException);
                return(false);
            }
            catch (Exception generalException)
            {
                MessageFunctions.Error("Error finding matching staff member", generalException);
                return(false);
            }
        }
コード例 #28
0
 /// <summary>
 ///     Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 /// </summary>
 void IDisposable.Dispose( )
 {
     _rngCsp.Dispose( );
 }
コード例 #29
0
ファイル: CryptoRNG.cs プロジェクト: RushuiGuan/framework
 public void Dispose()
 {
     provider.Dispose();
 }
コード例 #30
0
 public void Dispose()
 {
     rdm.Dispose();
 }