Click here to Skip to main content
16,017,852 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi guys. Hope someone can help me ! I am using C# windows application with a Firebird database. When the program starts you have to log in to the firebird server with a username and password. For certain functions in the program classes get instantiated, and you have to reconnect to the database to execute commands against it. My question is : what will be the best way to save the username and password? in a global variable or is it possible to only connect once to the server for the entire live span of a user log in ?

can anyone please help?

thanks
Posted

1 solution

Store the username and password using the Settings-functionality in the project-properties window. These are global variables. If you add two user-settings as strings, you automatically store the username and password in a xml-file under the current windows user. To make the password unreadable to the naked eye you can base64-convert the string.

The settings properties are accessed form code like this:
C#
// Saving the username. Saved as "QW11bmQ="
string userName = "Amund";
byte[] bytearray = Encoding.Default.GetBytes(userName);
string userName64 = Convert.ToBase64String(bytearray);
Properties.Settings.Default.UserName = userName64;
Properties.Settings.Default.Save();

// Loading the username from settings at application start-up
string _userName;
string userName64 = Properties.Settings.Default.UserName;
if(!userName64.Equals(String.Empty))
    _userName = Encoding.Default.GetString(Convert.FromBase64String(userName64));
 
Share this answer
 
v3
Comments
Tech Code Freak 29-Jul-11 10:28am    
My 5!

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