Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

TwisteR

Loading .txt or other text files

This topic is 6018 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I havn''t posted much latly, but, i got a question, How exactly would you go about loading a text file to get information, like say a password, and saving that password to a variable? i am using Microsoft Visual C++ 6.0 and I am making a dialog box that I would like to have password protection, or if you have a better way to make a password protected program, please help me! Thank you very much. Sincerly, TwisteR

Share this post


Link to post
Share on other sites
Advertisement
well, if you''re password protecting a setupfile, then you should hardcode it (or have it generate based on the user''s name/organization). if its a password to a program, you could
store an encrypted version in the windows registry.


-eldee
;another space monkey;

Share this post


Link to post
Share on other sites
In the application object file, add the following line of
code to the InitInstance(..) class member over-ride. this will
create a "CustomSoft" key in the system registry. You should use a label that is appropriate to your needs.
The first time that your application is closed,
the system will create a subkey under the "CustomSoft"
key using your application's file name less it's extension.


SetRegistryKey("CustomSoft");


Over-ride the OnShowWindow(...) class member in your main
frame class.

void CMainFrame::OnShowWindow(BOOL bShow, UINT nStatus)

{
CFrameWnd::OnShowWindow(bShow, nStatus);
char cPass = AfxGetApp()->GetProfileString("YourApp", "Password", NULL) // if you encrypted the password, you'd decrypt it here
// you may also want to change "password" to something misleading ;>
// pop up your password dialog here, and then test it against the correct password.
if(cAttempt == cPass)
{
// do something cool
}
}


this code isn't tested, so dont copy/paste it and expect it to work...
my advice to you is to pick up a hefty VC++ book.

-eldee
;another space monkey;

Edited by - eldee on December 26, 2001 12:29:32 AM

Share this post


Link to post
Share on other sites
In case you want to open regular text files (not for passwords, but other stuff), I'd recommend using fstreams, mainly because they are easy to use and are pretty flexible.

They work just like cout and cin, but are for files.
Simply do #include <fstream.h> and then you can create fstream objects (ifstream for input or ofstream for output)
Here's some sample code:


(if you want to read in a file)
ifstream f;
char strMyName[256];
f.open("c:\somefile.txt", ios::in);
f>>strMyName;
f.close();



Edited by - RelisH on December 27, 2001 10:40:03 AM

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!