Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using mysql workbench and making a c# application, and in connection string my password is visible. How to write the line of code without exposing the password?

What I have tried:

    class DB
    {
        private MySqlConnection connection = new MySqlConnection("server=localhost;port=3306;username=root;password=password;database=database");
        
        public void openConnection()
        {
            if(connection.State == System.Data.ConnectionState.Closed)
            {
                connection.Open();
            }
        }

        public void closeConnection()
        {
            if (connection.State == System.Data.ConnectionState.Closed)
            {
                connection.Close();
            }
        }

        public MySqlConnection getConnection()
        {
            return connection;
        }
    }
}


Please help!
My app will be reviewed by someone so I need to make sure that my password is not visible.
Posted
Updated 19-Jan-23 23:07pm

You wouldn't normally hard-code your connection string in your code. You normally put it in the apps app.config file.

You can then encrypt the the connectionstring section of the config file.

See Connection Strings and Configuration Files | Microsoft Docs[^].
 
Share this answer
 
Comments
Maciej Los 16-Sep-19 3:15am    
5ed!
Normally you would read the documentation for the platform you are using:
Protecting Connection Information | Microsoft Docs[^]
 
Share this answer
 
Comments
Maciej Los 16-Sep-19 3:15am    
5ed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900