/// <summary>
        ///     Sets the password.
        /// </summary>
        /// <param name="account">The account.</param>
        private void SetPassword(Account account)
        {
            var newPassword = new NewPassword( );

            newPassword.ShowDialog( );

            var vm = newPassword.DataContext as NewPasswordViewModel;

            if (vm?.CloseWindow != null && vm.CloseWindow.Value)
            {
                string input = vm.Password1;

                if (string.IsNullOrEmpty(input))
                {
                    return;
                }

                HashSettings hashSettings = HashSettings.GetHashSettings( );

                // Create the salt data
                byte[] salt = GetRandomBytes(hashSettings.SaltBytesCount);

                // Hash the input using the specified salt and settings.
                byte[] hash = CreateSaltedHash(input, salt, hashSettings.IterationsCount, hashSettings.HashBytesCount);

                // Encode the hash as a string
                string saltedHash = EncodeSaltedHash(hashSettings.Version, salt, hash);

                var databaseManager = new DatabaseManager(PluginSettings.DatabaseSettings);

                const string commandText = @"--ReadiMon - SetPassword
DECLARE @contextInfo VARBINARY(128) = CONVERT( VARBINARY(128), 'User Accounts->Set Password' )
SET CONTEXT_INFO @contextInfo

DECLARE @password BIGINT = dbo.fnAliasNsId( 'password', 'core', @tenantId )

UPDATE Data_NVarChar SET Data = @value WHERE EntityId = @entityId AND TenantId = @tenantId AND FieldId = @password";

                try
                {
                    using (SqlCommand command = databaseManager.CreateCommand(commandText))
                    {
                        databaseManager.AddParameter(command, "@entityId", account.Id);
                        databaseManager.AddParameter(command, "@tenantId", account.TenantId);
                        databaseManager.AddParameter(command, "@value", saltedHash);

                        command.ExecuteNonQuery( );
                    }
                }
                catch (Exception exc)
                {
                    PluginSettings.EventLog.WriteException(exc);
                }
            }
        }
示例#2
0
        /// <summary>
        ///     Gets the hash settings given a specified version.
        /// </summary>
        /// <param name="version">The version.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentOutOfRangeException">version</exception>
        public static HashSettings GetHashSettings(int version = HashVersion11)
        {
            HashSettings settings;

            switch (version)
            {
            case HashVersion10:
                settings = new HashSettings
                {
                    Version         = version,
                    SaltBytesCount  = SaltSizeV10,
                    HashBytesCount  = HashSizeV10,
                    IterationsCount = IterationsCountV10
                };
                break;

            case HashVersion11:
                settings = new HashSettings
                {
                    Version         = version,
                    SaltBytesCount  = SaltSizeV11,
                    HashBytesCount  = HashSizeV11,
                    IterationsCount = IterationsCountV11
                };
                break;

            default:
                settings = null;
                break;
            }

            if (settings == null)
            {
                throw new ArgumentOutOfRangeException(nameof(version));
            }

            return(settings);
        }