/// <summary>
        /// This method saves the current settings back to the app.config file.
        /// </summary>
        public bool SaveLogin(ApplicationLogin login)
        {
            // initial value
            bool saved = false;

            // if the login exists
            if (login != null)
            {
                // first check if save password is true or not
                if (!login.SavePassword)
                {
                    // set password to null
                    login.Password = null;
                }

                // Encrypt Each Property
                string encryptedPassword = "";

                // if the save password exists
                if (login.HasPassword)
                {
                    // Save Login Information

                    // set the encrypted password
                    encryptedPassword = CryptographyManager.EncryptString(login.Password);

                    // Set the EncryptedPassword
                    this.UpdateKey("ApplicationPassword", encryptedPassword);
                }

                // encrypt the user name
                string encryptedUserName = CryptographyManager.EncryptString(login.UserName);

                // save the user name
                this.UpdateKey("ApplicationUserName", encryptedUserName);
            }
            else
            {
                // add to the validation errors
                this.ValidatationErrors += "The login does not exist.";

                // did not save
                saved = false;
            }

            // return value
            return(saved);
        }
        /// <summary>
        /// This event is fired when the 'EncryptAndCopyButton' is clicked.
        /// </summary>
        private void EncryptAndCopyButton_Click(object sender, EventArgs e)
        {
            // locals
            string connectionString = this.ConnectionstringControl.Text;
            string encryptionKey    = String.Empty;
            bool   useEncryption    = UseCustomKeyCheckBox.Checked;

            // If the connectionString string exists
            if (TextHelper.Exists(connectionString))
            {
                // if the value for useEncryption is true
                if (useEncryption)
                {
                    // set the encryptionKey
                    encryptionKey = EncryptionKeyControl.Text;
                }

                // If the encryptionKey string exists
                if (TextHelper.Exists(encryptionKey))
                {
                    // Encrypt the Connection String
                    string encryptedConnectionString = CryptographyManager.EncryptString(this.ConnectionstringControl.Text, encryptionKey);

                    // Copy the encryptedConnectionString to the clipboard
                    Clipboard.SetText(encryptedConnectionString);

                    // Set the text
                    this.StatusLabel.Text = "Encrypted and copied.";

                    // Show Success Message
                    this.StatusImage.BackgroundImage = Properties.Resources.Success;

                    // Show the user a message
                    ShowCopiedImage();
                }
                else
                {
                    // Show a message the encryption key is required
                    this.StatusLabel.Text            = "Encryption Key Is Required.";
                    this.StatusImage.BackgroundImage = Properties.Resources.Failure;
                }
            }
            else
            {
                this.StatusLabel.Text            = "Connection String Is Required.";
                this.StatusImage.BackgroundImage = Properties.Resources.Failure;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// This method saves the current settings back to the app.config file.
        /// </summary>
        public void SaveLoginInformation(string applicationUserName, string applicationPassword, bool savePassword)
        {
            // first check if save password is true or not
            if (!savePassword)
            {
                // set password to null
                applicationPassword = null;
            }

            // Encrypt Each Property
            string encryptedPassword     = CryptographyManager.EncryptString(applicationPassword);
            string encryptedUserName     = CryptographyManager.EncryptString(applicationUserName);
            string encryptedSavePassword = CryptographyManager.EncryptString(savePassword.ToString());

            // Save Login Information
            this.UpdateKey("ApplicationPassword", encryptedPassword);
            this.UpdateKey("ApplicationUserName", encryptedUserName);
            this.UpdateKey("SavePassword", encryptedSavePassword);
        }
        /// <summary>
        /// This method saves the current settings back to the app.config file.
        /// </summary>
        public bool SaveConnection(ConnectionInfo connection)
        {
            // initial value
            bool saved = false;

            // set the connection
            this.ConnectionInfo = connection;

            // locals
            string encryptedConnectionString = "";
            string encryptedDatabaseName     = "";
            string encryptedDatabasePassword = "";
            string encryptedDatabaseServer   = "";
            string encryptedDatabaseUserName = "";

            // if the connection exists
            if (connection != null)
            {
                // if the connection is valid
                if (connection.Validate())
                {
                    // if the connection string is set
                    if (connection.HasConnectionString)
                    {
                        // if the EncryptionKey has been set
                        if (this.HasEncryptionKey)
                        {
                            // encrypted the connection string
                            encryptedConnectionString = CryptographyManager.EncryptString(connection.ConnectionString, this.EncryptionKey);
                        }
                        else
                        {
                            // encrypted the connection string
                            encryptedConnectionString = CryptographyManager.EncryptString(connection.ConnectionString);
                        }

                        // Update the connection string
                        this.UpdateKey("ConnectionString", encryptedConnectionString);
                    }
                    else
                    {
                        // if the EncryptionKey has been set
                        if (this.HasEncryptionKey)
                        {
                            // encrypt each string with a password
                            encryptedDatabaseName     = CryptographyManager.EncryptString(this.ConnectionInfo.DatabaseName, this.EncryptionKey);
                            encryptedDatabasePassword = CryptographyManager.EncryptString(this.ConnectionInfo.DatabasePassword, this.EncryptionKey);
                            encryptedDatabaseServer   = CryptographyManager.EncryptString(this.ConnectionInfo.DatabaseServer, this.EncryptionKey);
                            encryptedDatabaseUserName = CryptographyManager.EncryptString(this.ConnectionInfo.DatabaseUserName, this.EncryptionKey);
                        }
                        else
                        {
                            // encrypt each string without password
                            encryptedDatabaseName     = CryptographyManager.EncryptString(this.ConnectionInfo.DatabaseName);
                            encryptedDatabasePassword = CryptographyManager.EncryptString(this.ConnectionInfo.DatabasePassword);
                            encryptedDatabaseServer   = CryptographyManager.EncryptString(this.ConnectionInfo.DatabaseServer);
                            encryptedDatabaseUserName = CryptographyManager.EncryptString(this.ConnectionInfo.DatabaseUserName);
                        }

                        // now update each keys
                        this.UpdateKey("DatabaseName", encryptedDatabaseName, false);
                        this.UpdateKey("DatabasePassword", encryptedDatabasePassword, false);
                        this.UpdateKey("DatabaseServer", encryptedDatabaseServer, false);
                        this.UpdateKey("DatabaseUserName", encryptedDatabaseUserName, true);
                    }

                    // set saved to true
                    saved = true;
                }
                else
                {
                    // add to the validation errors
                    this.ValidatationErrors += "The connection does not validate.";

                    // did not save
                    saved = false;
                }
            }
            else
            {
                // add to the validation errors
                this.ValidatationErrors += "The connection does not exist.";

                // did not save
                saved = false;
            }

            // return value
            return(saved);
        }