I have done a windows form application that I have debugged in "Release Mode".

I need to ask 2 questions at the same time because I think they depend on eachother and that is my questionmark:

1. When starting this program, there will be a panel visible where you will enter: UserName and Password and when you write these correct the panel will be panel1->Visible = false; and some other buttons on the form will be ->Enabled = true; etc...

2. Now is the question also when you have written the correct Username and password I would like the panel to never show up again as you have written the correct one, once.

How would this be possible to do ?

I know that I could create a .txt file that contains any information under for example: C:\\Windows\\registerdoc.txt
that the application reads from in order to not show the panel1 but can this really be the correct way to do this and other computers perheps doesn´t use C:\\ but for example G:\\ and so on ?

Recommended Answers

All 7 Replies

That is a correct way to do it but if you want to make it more portable for computers with G:\\ you would have to find a way to construct a filepath depending on the computer it is running on, a library prehaps?

Under MS-Windows the correct way to do it is to save the UserName and Password in the registry -- and encrypt the password because the registry can be easily viewed by anyone. Its not very difficult to read/write to the registry, but here is a c++ class if you want one. I'm sure you will find others if you google for "c++ registry class" or something like that.

When your program starts the first thing it should do is check the registry to see if the UserName and Password exists. If it does not exist in the registery than prompt for them as you suggested. If they doe exist in the registry then don't prompt.

>> Under MS-Windows the correct way to do it is to save the UserName and Password in the registry -- and encrypt the password

Thank you for this information. I have looked at the class code that was linked in the previous post and also googled around a lot of things about this subject but find it hard to understand of how to do. ("It is not really ordinary C++")

I do understand the logic of that I would check against the registry if user/password is registered there as encrypted etc and take this into considiration when promting the registerpanel or not in the application.

To be honest I have no clue of how to begin this. I dont know where and how I will put this Username and password in the registry. (I dont know what is what here really in the registry/regedit).

Would I put the class CRegistry{}; outside the Form class{}; as a beginning ?
And from here I would begin to do something. The ordinary C++ code will not be any problem, only the syntax and calls and how and where to write and read things from the registry(regedit) etc...
If I could get a startingpoint in where to understand of how to do this, that would be wonderful. I find this very interesting to learn...

Thank you


Under MS-Windows the correct way to do it is to save the UserName and Password in the registry -- and encrypt the password because the registry can be easily viewed by anyone. Its not very difficult to read/write to the registry, but here is a c++ class if you want one. I'm sure you will find others if you google for "c++ registry class" or something like that.

When your program starts the first thing it should do is check the registry to see if the UserName and Password exists. If it does not exist in the registery than prompt for them as you suggested. If they doe exist in the registry then don't prompt.

In simple words:

How would I work with the Registry (Regedit) programatically in order to save Username from textBox1->Text and Password from textBox2->Text.

How will I in an encrypted way store/write these to the registry and how will I then read from the registry to understand that These has been registrated there ?

I have found this link:
http://www.codeguru.com/columns/dotnettips/article.php/c8859

Here they are talking about ex: "Creating a New Registry Key and Value"
Is this close to what I want to do etc... ?

After research I have found and been able to set up this code.
What happens when running this code is that I will in "RegEdit" create:
HKEY_CURRENT_USER\\Software\\My Product
and 2 keys to that.

What I wonder is when doing this, it works on XP Proffessional as I have.
Will this path: (HKEY_CURRENT_USER\\Software)
also be found in:
XP Home Edition
Windows Vista
Linux
Unix / Variants
Windows 98
Windows ME
Windows NT
Windows 2000
Windows server 2003

How portable is the code below ? What path would be the one that all of the above Operative systems have by default and for the below code to work... ?

RegistryKey^ currentUser;
RegistryKey^ softwareKey;

try
{
RegistryKey^ currentUser = Microsoft::Win32::Registry::CurrentUser;
RegistryKey^ softwareKey = Microsoft::Win32::Registry::CurrentUser->CreateSubKey("Software\\My Product");

softwareKey->SetValue("Description", "Description of my product");
softwareKey->SetValue("Version", "1.42");

}
	 catch(Exception^ ex)
	 {
		 MessageBox::Show(ex->Message);
	 }
	 __finally
	 {
		 if(softwareKey) softwareKey->Close();
		 if(currentUser) currentUser->Close();
	 }

Those registry functions are only available on MS-Windows 2000 and newer. They are definitely not available on *nix, and possibly not on Win95/98/Me/NT

If you want complete portability then I would suggest you store them in an encrypted file instead of the windows registry.

Okay, I beleive this is what I want to do then.
To store them in an encrypted file. Is this files like *.ini ?

If I will store this encrypted file under C:\\
How is an encrypted file created. How do I make an encrypted file
out of Username: user1 and Password: secret1

Then I would also need to read this encrypted file in order to check that the user/password is correct ?
I have only worked with read/write with .txt files before.

Those registry functions are only available on MS-Windows 2000 and newer. They are definitely not available on *nix, and possibly not on Win95/98/Me/NT

If you want complete portability then I would suggest you store them in an encrypted file instead of the windows registry.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.