Thread: Password help

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    183

    Unhappy Password help

    Hi every one. I have only been programming for a few months now , and I am already stuck.

    I have currently been trying to develop a new security program for websites , but have come across a few minor difficulties - when the user types the password , any one can see it. I need a way of replacing any characters with *.

    Here is the code so far :

    Code:
    #include <iostream>
    #include <cstring>
    
    using namespace std;
    
    int main()
    
    {
        
        char userid[501];
        char password[501];
        
        cout<<"Security program initiated.\n\n\n\n";
        cout<<"Enter your user ID : ";
        cin.getline (userid , 501 );
        
        cout<<"\nEnter your password : ";
        cin.getline (password , 501 );
        
        while (strcmp (userid, "41149512")== 1||strcmp ( password, "solaris" ) == 1 ) {
            cout<<"\n\n\nInvalid user ID or password. Please try again.\n\n\n";
            cout<<"Enter your user ID : ";
            cin.getline (userid , 501 );
            
            cout<<"\nEnter your password : ";
            cin.getline (password , 501 );
        };
        
        if (strcmp ( userid, "41149512" ) == 0&&strcmp ( password, "solaris" ) == 0 ){
            cout<<"\n\n\nVerifying user ...\n\nUser identified.\nWelcome back.\n\n\n<< Press Enter to continue >>";
        };
        
        cin.get();
        return 0;
    }
    Also , it comes up with lots of errors on line 54 , but there are only 35 lines in the program according to the compiler.

    This is really confusing me. I think it may be a header file , but I'm not sure. Please help !

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > any one can see it. I need a way of replacing any characters with *.
    Then you need to say which OS and compiler you're using.

    > Also , it comes up with lots of errors on line 54
    Post those errors then - we all have different compilers.

    > while (strcmp (userid, "41149512")== 1||strcmp ( password, "solaris" ) == 1 )
    Check the return result of strcmp in the manual.
    == 1 is not what you want
    != 0 probably is.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    183
    Compiler : Dev C++
    Errors :

    54 C:\PROGRAM FILES\DEV-CPP\include\c++\3.3.1\bits\stl_algobase.h:67, from C:\PROGRAM FILES\DEV-CPP\include\c++\3.3.1\memory In file included from C:/PROGRAM FILES/DEV-CPP/include/c++/3.3.1/bits/stl_algobase.h:67, from C:/PROGRAM FILES/DEV-CPP/include/c++/3.3.1/memory

    48 C:\PROGRAM FILES\DEV-CPP\include\c++\3.3.1\memory:54, from C:\PROGRAM FILES\DEV-CPP\include\c++\3.3.1\string from C:/PROGRAM FILES/DEV-CPP/include/c++/3.3.1/memory:54, from C:/PROGRAM FILES/DEV-CPP/include/c++/3.3.1/string

    47 C:\PROGRAM FILES\DEV-CPP\include\c++\3.3.1\string:48, from C:\PROGRAM FILES\DEV-CPP\include\c++\3.3.1\bits\locale_classes.h from C:/PROGRAM FILES/DEV-CPP/include/c++/3.3.1/string:48, from C:/PROGRAM FILES/DEV-CPP/include/c++/3.3.1/bits/locale_classes.h

    47 C:\PROGRAM FILES\DEV-CPP\include\c++\3.3.1\bits\locale_classes.h:47, from C:\PROGRAM FILES\DEV-CPP\include\c++\3.3.1\bits\ios_base.h from C:/PROGRAM FILES/DEV-CPP/include/c++/3.3.1/bits/locale_classes.h:47, from C:/PROGRAM FILES/DEV-CPP/include/c++/3.3.1/bits/ios_base.h

    49 C:\PROGRAM FILES\DEV-CPP\include\c++\3.3.1\bits\ios_base.h:47, from C:\PROGRAM FILES\DEV-CPP\include\c++\3.3.1\ios from C:/PROGRAM FILES/DEV-CPP/include/c++/3.3.1/bits/ios_base.h:47, from C:/PROGRAM FILES/DEV-CPP/include/c++/3.3.1/ios

    45 C:\PROGRAM FILES\DEV-CPP\include\c++\3.3.1\ios:49, from C:\PROGRAM FILES\DEV-CPP\include\c++\3.3.1\ostream from C:/PROGRAM FILES/DEV-CPP/include/c++/3.3.1/ios:49, from C:/PROGRAM FILES/DEV-CPP/include/c++/3.3.1/ostream

    45 C:\PROGRAM FILES\DEV-CPP\include\c++\3.3.1\ostream:45, from C:\PROGRAM FILES\DEV-CPP\include\c++\3.3.1\iostream from C:/PROGRAM FILES/DEV-CPP/include/c++/3.3.1/ostream:45, from C:/PROGRAM FILES/DEV-CPP/include/c++/3.3.1/iostream

    1 C:\PROGRAM FILES\DEV-CPP\include\c++\3.3.1\iostream:45, from Templates\danpassword.cpp from C:/PROGRAM FILES/DEV-CPP/include/c++/3.3.1/iostream:45, from Templates/danpassword.cpp

    1 C:\Program Files\Dev-Cpp\Templates\danpassword.cpp from Templates/danpassword.cpp

    108 C:\PROGRAM FILES\DEV-CPP\include\c++\3.3.1\cstdlib `rand' not declared


    Changed == 1 to != 0 : Does not work.

    Thanks for the help anyway.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Works for me
    Code:
    #include <iostream>
    #include <cstring>
    
    using namespace std;
    
    int main()
    
    {
        
        char userid[501];
        char password[501];
        
        cout<<"Security program initiated.\n\n\n\n";
        cout<<"Enter your user ID : ";
        cin.getline (userid , 501 );
        
        cout<<"\nEnter your password : ";
        cin.getline (password , 501 );
        
        while (strcmp (userid, "41149512") != 0 || strcmp ( password, "solaris" ) != 0 ) {
            cout<<"\n\n\nInvalid user ID or password. Please try again.\n\n\n";
            cout<<"Enter your user ID : ";
            cin.getline (userid , 501 );
            
            cout<<"\nEnter your password : ";
            cin.getline (password , 501 );
        };
        
        if (strcmp ( userid, "41149512" ) == 0 && strcmp ( password, "solaris" ) == 0 ) {
            cout<<"\n\n\nVerifying user ...\n\nUser identified.\n"
                  "Welcome back.\n\n\n<< Press Enter to continue >>";
        };
        
        cin.get();
        return 0;
    }
    > 1 C:\Program Files\Dev-Cpp\Templates\danpassword.cpp from Templates/danpassword.cpp
    Does this mean your source code is in the same directory structure as the compiler?

    This is a really bad idea - create a whole new directory (say c:\coding) where you can put all your own code.

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    183
    That ... works for you ... Really ???
    No errors ??? Oh well , I'll figure somthin' out.


    So anyway , is there any way to change the input to * ? I really need to put these on to the program , because when I go on web site , very often at school , people will see the password.

    I was trying to make one of those little login window aps , but they seem really complicated , especially for the likes of me.

    Any help will be greatly appriciated.
    Thanks

  6. #6
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    >>any one can see it. I need a way of replacing any characters with *.
    Many compilers will come with the header <conio.h>, which will often come with the function getch(). Be warned, it is nonstandard and will not be included in every compiler - and won't be reliably portable either.

    It's useful, because it alllows you to input a single character, without echoing it to the screen. Then you just output a * every time a character is read. So this is something like what you want:
    Code:
    char input;			//To store each character that we read
     std::string password;  //To store the complete string
     
     while((input = getch()) != '\n') //Keep reading characters until 'enter' is pressed
     {
        password += input; //Push each character to the back of the string
        std::cout << '*';  //Display a *
     }
     
     if(password == "solaris") //Check if it's correct...
     ... etc.
    You can tailor it to your needs, ask questions if you don't know how some of the stuff works.

    Hope this helps!

    **P.S.
    I was trying to make one of those little login window aps , but they seem really complicated , especially for the likes of me.
    I'm glad you know your own limits It can be very frustrating if you don't.
    Last edited by Hunter2; 01-04-2005 at 06:12 PM.
    Just Google It. √

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

  7. #7
    Registered User
    Join Date
    Nov 2004
    Location
    Pennsylvania
    Posts
    434
    2 things:

    1.)
    Code:
    if(strcmp(password, "solaris") !=0)
    if you say !=0 that's like saying while it isn't true right?
    i thought 0 was true and 1 was false.


    2.) Secondly when you get your program up and running you should try an encryption scheme on the password and save the encrypted password in a file. Anyone with a decompiler or hex editor can figure out the password if it is hardcoded into the program. I would suggest Hashing it and then just comparing hash values it is very secure(the chances of two hash values being the same is 1 : (2 to the 256th power); that's what most websites use) MD5 or SHA are good (google it you'll get tons of crap)

    Good Luck!

  8. #8
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    I think at least from an assembly perspective.. whenever a cmp comparison is made between two operands, it performs an implied subtraction.. and returns 0 if they are the same.

    As far as encryption goes.. there will always be one big downside... no matter how much you scramble, hash, hide, maniuplate, map, ,mask, rotate, xor, bit shift etc.. there will always be a way to decrypt all the work you've done to hide your password. (yes, some schemes are wicked harder than others, but even the most technical encryption scheme has to be decrypted)
    Last edited by The Brain; 01-05-2005 at 02:44 AM.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  9. #9
    Registered User Kybo_Ren's Avatar
    Join Date
    Sep 2004
    Posts
    136
    A hash cannot be decrypted. You can find data whose hash is the same as the hash you have, but you can never be sure which one is the right one (and there are infinite solutions).

  10. #10
    Registered User
    Join Date
    Jan 2005
    Posts
    183
    Thank you all for your help. It was most helpful.

    But there's still one more problem - I used all your advice , but I can't compile it , 'cause It still comes up with them wierd errors. Does anyone know how to get rid of them ?

    ( Errors 3rd message down on this page. )

    Thanks again !

    PS.
    Why are you people extremely clever ?
    Last edited by Necrofear; 01-05-2005 at 10:21 AM.

  11. #11
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Which version of Dev-C++ do you have?

    Dev-C++ 5 Beta 9 (4.9.9.1) should be the one

  12. #12
    Registered User
    Join Date
    Nov 2004
    Location
    Pennsylvania
    Posts
    434
    As far as encryption goes.. there will always be one big downside... no matter how much you scramble, hash, hide, maniuplate, map, ,mask, rotate, xor, bit shift etc.. there will always be a way to decrypt all the work you've done to hide your password. (yes, some schemes are wicked harder than others, but even the most technical encryption scheme has to be decrypted)
    Just letting you know...Your right. The only problem is with algoriths like DES, Triple-DES, GOST and other highly advanced algorithms would take a very long time to decrypt. Even though these schemes are even based around the XOR function they add unpredictable elements to the mix. The only way to decrypt these would be through a brute force attack...

    By the way it would take a $10 Trillion Dollar Super-Computer about 1,000,000,000,000 (10^11) years to decipher a 128-Bit key using brute force (which is the only way to break these ciphers). So your right if you think that someone is going to spend $10 T dollars and waste 100..... years of their time doing this.

    Just remember the longer your key is the safer your message is (a 40 bit key can be solved in .02 microseconds using the same computer)!

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