opening files from a program
-
Hi all. I thought yesterday of creating a very simple encryption program using a basic if/else statement. This is the basic idea for it. #include int main() { int const pword = (whatever your password is); float password cout << "To open program, enter the password: << endl; cin >> password; if (password = (password)) { // this is where i have a problem, how do you open a file from a program? } else { cout << "Access Denied" << endl; } return 0; } Please help or comment on this or my idea in any way. Is this even a good idea? A workable idea? Thanks in advance.
-
Hi all. I thought yesterday of creating a very simple encryption program using a basic if/else statement. This is the basic idea for it. #include int main() { int const pword = (whatever your password is); float password cout << "To open program, enter the password: << endl; cin >> password; if (password = (password)) { // this is where i have a problem, how do you open a file from a program? } else { cout << "Access Denied" << endl; } return 0; } Please help or comment on this or my idea in any way. Is this even a good idea? A workable idea? Thanks in advance.
if you want an external program to open with the file (like notepad, for instance...) use the you could system() command. like:
if(password == paswd)
{
system("notepad file.txt");
}that comes from the command prompt commands. you can actually type "notepad file.txt" in a command prompt, and it will execute notepad, with the file. There's other ways using various window commands to open applications, but thats a pretty simple way. *.* cin >> knowledge;
-
Hi all. I thought yesterday of creating a very simple encryption program using a basic if/else statement. This is the basic idea for it. #include int main() { int const pword = (whatever your password is); float password cout << "To open program, enter the password: << endl; cin >> password; if (password = (password)) { // this is where i have a problem, how do you open a file from a program? } else { cout << "Access Denied" << endl; } return 0; } Please help or comment on this or my idea in any way. Is this even a good idea? A workable idea? Thanks in advance.
There are several options. Here are a few: - standard C++ lib: - MFC: CFile, CstdioFile - Win32 API: CreateFile() “…is this even a good idea…” No. There are so many reasons but the most obvious is nothing is encrypted. It appears your intent was to “password protect” a file but it only works if the file is opened with your app. What’s to stop someone from opening the file with notepad.exe for example. You have hard-coded the password into the code. Bad idea. With little effort, someone could just open your compiled exe with a hex editor and nab the password. The list goes on (and its long). Encryption is a very complex subject. If you are seriously interested consider picking up a copy of Bruce Shneier’s Applied Cryptography. you wrote: “ if(password = (password)) “ what you meant was: if(password == pword)… I have seen some of your other posts on this forum and I am not sure what compelled me to answer this one. I would suggest searching www.msdn.microsoft.com and google for your questions and if they still remain unanswered, post them as a question. “How to open a file” can be answered in less than 1 minute by searching the above sites
-
There are several options. Here are a few: - standard C++ lib: - MFC: CFile, CstdioFile - Win32 API: CreateFile() “…is this even a good idea…” No. There are so many reasons but the most obvious is nothing is encrypted. It appears your intent was to “password protect” a file but it only works if the file is opened with your app. What’s to stop someone from opening the file with notepad.exe for example. You have hard-coded the password into the code. Bad idea. With little effort, someone could just open your compiled exe with a hex editor and nab the password. The list goes on (and its long). Encryption is a very complex subject. If you are seriously interested consider picking up a copy of Bruce Shneier’s Applied Cryptography. you wrote: “ if(password = (password)) “ what you meant was: if(password == pword)… I have seen some of your other posts on this forum and I am not sure what compelled me to answer this one. I would suggest searching www.msdn.microsoft.com and google for your questions and if they still remain unanswered, post them as a question. “How to open a file” can be answered in less than 1 minute by searching the above sites
-
Hi all. I thought yesterday of creating a very simple encryption program using a basic if/else statement. This is the basic idea for it. #include int main() { int const pword = (whatever your password is); float password cout << "To open program, enter the password: << endl; cin >> password; if (password = (password)) { // this is where i have a problem, how do you open a file from a program? } else { cout << "Access Denied" << endl; } return 0; } Please help or comment on this or my idea in any way. Is this even a good idea? A workable idea? Thanks in advance.
HackerBoy wrote: if (password = (password)) This is an error and is common for beginners. Get into the habit now of putting constants on the left of the equality operator and the compiler will be quick to tell you when you've mistakingly used the assignment operator instead. Otherwise, while what you have is syntactically correct, it does not produce the desired result. HackerBoy wrote: ...how do you open a file from a program? I'm not quite sure what you mean by this. There are many ways to open files. Among them are
CreateFile()
,fopen()
, andCFile::Open()
.
A rich person is not the one who has the most, but the one that needs the least.