Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. opening files from a program

opening files from a program

Scheduled Pinned Locked Moved C / C++ / MFC
helpsecurityquestion
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    HackerBoy
    wrote on last edited by
    #1

    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.

    K M D 3 Replies Last reply
    0
    • H HackerBoy

      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.

      K Offline
      K Offline
      keegan
      wrote on last edited by
      #2

      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;

      1 Reply Last reply
      0
      • H HackerBoy

        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.

        M Offline
        M Offline
        Michael Gunlock
        wrote on last edited by
        #3

        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

        H 1 Reply Last reply
        0
        • M Michael Gunlock

          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

          H Offline
          H Offline
          HackerBoy
          wrote on last edited by
          #4

          Thanks for the answers, sorry if they seem easy or whatnot. I am very new at programming.

          1 Reply Last reply
          0
          • H HackerBoy

            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.

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            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(), and CFile::Open().


            A rich person is not the one who has the most, but the one that needs the least.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups