Thread: passward program

  1. #1
    Registered User zarishize's Avatar
    Join Date
    May 2011
    Posts
    3

    passward program

    hey sir,... i wana make a passward program but not getting how?/ would u like to help me plzz.... but that programming must b easy so i could easily understand .. bcoz m a begineeer of c language .. :/ ..

  2. #2
    Registered User xentaka's Avatar
    Join Date
    May 2011
    Posts
    60

    Well..

    Need a bit more information on what exactly you are trying to accomplish. Writing a simple program that would ask for a password before continuation would be something like:

    Code:
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    int main()
    {
        string passwdOne;
    
        cout << "Please enter the password : ";
        getline(cin, passwdOne);
        if (passwdOne == "yourpasswordhere") {
            cout << endl << "stuff goes here" << endl;
        }
    
        return 0;
    
    }
    This is simplistic of course, but like I said before it depends on what you are trying to accomplish.

  3. #3
    Registered User KyussRyn's Avatar
    Join Date
    Mar 2009
    Location
    Tokyo, Japan
    Posts
    7
    I would probably change the line
    Code:
        if (passwdOne == "yourpasswordhere") {
            cout << endl << "stuff goes here" << endl;
        }
    code to comparing individual characters:
    Code:
    bool result;
    int size;
    size = passwdOne.length();
    for( int x = 0; x < size; x++ ) {
        if( passwdOne[x] != passwdTwo[x] ) {
            result = false;
            break;
        }
        result = true;
    }
    Or something like this.

  4. #4
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    Usually you never want to store the password. Instead you should apply a hash function the password, and compare it to a stored hash of the correct password. That way the is no way to obtain the password from the program if you don't know it.


    Quote Originally Posted by KyussRyn View Post
    I would probably change the line
    Code:
        if (passwdOne == "yourpasswordhere") {
            cout << endl << "stuff goes here" << endl;
        }
    code to comparing individual characters:
    Code:
    bool result;
    int size;
    size = passwdOne.length();
    for( int x = 0; x < size; x++ ) {
        if( passwdOne[x] != passwdTwo[x] ) {
            result = false;
            break;
        }
        result = true;
    }
    Or something like this.
    What for?
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 03-03-2009, 04:47 PM
  2. Get program to copy itself into program files, then start on startup.
    By guitarist809 in forum Windows Programming
    Replies: 6
    Last Post: 03-03-2008, 09:42 AM
  3. Replies: 5
    Last Post: 08-16-2007, 11:43 PM
  4. Replies: 18
    Last Post: 11-13-2006, 01:11 PM
  5. Math Equation Program (I can't find the problem with my program!)
    By masked_blueberr in forum C Programming
    Replies: 14
    Last Post: 07-06-2005, 11:53 AM