Thread: Password

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    2

    Password

    I am stupid:
    How do I make a password protected file?

  2. #2
    Registered User
    Join Date
    Mar 2004
    Posts
    220
    >How do I make a password protected file?

    There are many ways, but we need to know what type of protection your looking for.....

    It's just too vague, are you looking for code that the user would have to enter in a password to continue in the program?

    Or are you looking for a utility that actually encrypts your program and decrypts it when the right password is input'd(this the right word?), something along those lines?

    Your question is too vague sorry, can't exactly answer that without more information.
    OS: Windows XP Pro CE
    IDE: VS .NET 2002
    Preferred Language: C++.

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    2

    Late Reply

    Umm...the first one, where you have to enter a password to continue and see the other stuff.

  4. #4
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    If you're talking about writing a password-protected program, it's as easy as:
    Code:
    std::string password;  //A string to hold the input
    std::cout << "Enter password: ";   //Ask for the password
    std::getline(std::cin, password);    //Let them type a password
    if(password != "my_password")     //Check if they got it right
    {
       std::cout << "You got the wrong password!";
       return 0;   //If they got the password wrong, quit.
    }
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  5. #5
    yes, I'm registered!!! algi's Avatar
    Join Date
    Nov 2004
    Location
    Ipswich
    Posts
    161

    Post

    Try this


    Code:
    #include <iostream>
    #include <string>
    
    int main()
    {
         cout<<"Enter password: ";
         cin>>password;
         cin.ignore();
         if ( password == "mypassword" )
         {
               cout<<"Password correct!";
               cin.get();
          }
    
           else
           {
            cout<<"Sorry password incorrect, Quitting";
           }
    }

  6. #6
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    A better method would be:
    1) Get password
    2) Apply encryption scheme (MD5 works)
    3) Check it against password that already has been encrypted

    the
    Code:
    if (password == "mypassword")
    method suffers one huge problem. I can open your executable with pretty much any text editor and see the password.

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Try this
    Too bad it won't work and has nothing to do with password protecting a file.
    My best code is written with the delete key.

  8. #8
    yes, I'm registered!!! algi's Avatar
    Join Date
    Nov 2004
    Location
    Ipswich
    Posts
    161
    Well sorry, i'm just trying to help. You don't need to get so uptight at me!

  9. #9
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >You don't need to get so uptight at me!
    You need to chill out a bit. I wasn't trying to slam you down.

    >Well sorry, i'm just trying to help.
    If you don't post working code, you're not helping. Start by compiling and testing everything you post until you're confident that you can write correct code off the top of your head. It saves you the headache of people constantly correcting you, and it also saves you the headache of confusing the very people you're trying to help.
    My best code is written with the delete key.

  10. #10
    yes, I'm registered!!! algi's Avatar
    Join Date
    Nov 2004
    Location
    Ipswich
    Posts
    161
    I'm sorry

  11. #11
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    A better method would be:
    1) Get password
    2) Apply encryption scheme (MD5 works)
    3) Check it against password that already has been encrypted
    Judging from "I am stupid:"
    It sounds like that might be a little over his head
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  12. #12
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    I know but I'm in one of those moods

  13. #13
    Registered User
    Join Date
    Dec 2004
    Posts
    48

    Post

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    
    {    
        float a_a, b_b;
        b_b = 123                                       //replace 123 with password
        cout<<"Please enter your password: \n";
        cin>> a_a;
        cin.ignore();
        
          if ( a_a == b_b ) {
              cout<<"Correct.\n";
              cin.get();
    }
          else if ( a_a != b_b ) {
              cout<<"Incorrect.\n";
              cin.get();
    }
    }
    I made this with correct syntax, but for some reason DEV gave me trouble when trying to copy / paste so I typed this. I was careful, but if it does not work like I typed it above I have made a typing mistake. This is what I would do, but for the record, I have only started learning to code 2 days ago. Although people could just pop it open with a program editor, most people have no idea about that. Here's my work. If you don't like it, don't use it. It works for me.

  14. #14
    yes, I'm registered!!! algi's Avatar
    Join Date
    Nov 2004
    Location
    Ipswich
    Posts
    161
    The problem with that password is that you can only have numbers

  15. #15
    Registered User
    Join Date
    Dec 2004
    Posts
    48

    Unhappy only numbers.....

    Sorry....as I said, I just starting learning C++ 2 days ago. I tried for a very long time, but couldn't get anything else to work .Sorry, that's the best I can do as a newbie programmer.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem reading a password from a file.
    By medeshago in forum C Programming
    Replies: 15
    Last Post: 12-21-2008, 07:20 AM
  2. [Q]Hide Password
    By Yuri in forum C++ Programming
    Replies: 14
    Last Post: 03-02-2006, 03:42 AM
  3. written command line password generator
    By lepricaun in forum C Programming
    Replies: 15
    Last Post: 08-17-2004, 08:42 PM
  4. Password prompt in unix w/o \b
    By rafe in forum C++ Programming
    Replies: 1
    Last Post: 10-09-2002, 08:54 AM
  5. password
    By hammers6 in forum C Programming
    Replies: 1
    Last Post: 10-10-2001, 12:14 AM