Thread: Password Problem

  1. #1
    Is Trying to Learn
    Join Date
    Mar 2006
    Location
    Hutton, Preston
    Posts
    215

    Password Problem

    Hi

    I am creating a username and password log in system and at the moment i am having problems.

    what i want at the moment is when you put in the password it will come up in the labe "OK" just so that i know it is working.

    here is the code i have at the moment

    Code:
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
    
     char Password;
     char guess;
    
     if (guess = Password)
     {
     lbOutput->Caption = "ok";
     }
    can anyone help?

    Thanks

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So, you have two uninitialized char variables (guess and password). You then assign guess to password, and check if it's non-zero, and set the caption to "ok".

    This all seems wrong to me.

    First of all, shouldn't password and guess be something that comes from the outside (e.g. parts of the form)? And I'm almost certain they should be strings rather than single chars...

    And you should COMPARE the guess with password, rather than assign it...

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Code:
    #include <string.h>
    
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
    
     char Password[256]; //need enough char's to fit the password + 1
     char guess[256];
    
    
    //now fill the Password from the source / database / ect
    
    //get the users input into 'guess'
    //from the Password edit on Form1 
    
    //compare char arrays ( == will not work )
    if( strcmp ( guess, Password) == 0) //are same
    {
              lbOutput->Caption = "ok";
    }
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  4. #4
    Is Trying to Learn
    Join Date
    Mar 2006
    Location
    Hutton, Preston
    Posts
    215
    update of the full code if it will help

    Code:
    void __fastcall TForm2::lbOutputClick(TObject *Sender)
    {
    char password[256];
    
    Application->MessageBox("Incorrect Password, Please Try again",
    				"Error - Incorrect Password",MB_ICONWARNING);
    
    edPassword->Clear();
    
    password = edPassword->Text;
    
    if ( edPassword == "administrator")
    {
    Form2->Close();
    Form1->Show();
    }
    else
    lbOutput->Visible = true;
    lbOutput->Caption = "Incorrect Password";
    }

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Shouldn't this

    if ( edPassword == "administrator")//you are using the EDIT control


    be

    if ( password == "administrator")//should be using the char array (text)




    but you can not (usually) do a string compare without using a class (CString or string)

    try

    if ( strcmp(password, "administrator") == 0 )//match, include <string.h>
    Last edited by novacain; 11-12-2007 at 05:49 PM.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  6. #6
    Is Trying to Learn
    Join Date
    Mar 2006
    Location
    Hutton, Preston
    Posts
    215
    i have change some of the items to what you have said but i believe the problem may be

    Code:
    password = edPassword->Text;
    but i am unsure how to fix this because it comes up with the error
    Code:
    LValue Required
    .

  7. #7
    Is Trying to Learn
    Join Date
    Mar 2006
    Location
    Hutton, Preston
    Posts
    215
    sorted it i think - thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A tenet connection from a C program..
    By ahmd2080 in forum Linux Programming
    Replies: 2
    Last Post: 07-04-2009, 03:42 AM
  2. Password Program
    By lukesowersby in forum C Programming
    Replies: 2
    Last Post: 03-23-2009, 11:36 AM
  3. Replies: 5
    Last Post: 11-07-2005, 11:34 PM
  4. searching problem
    By DaMenge in forum C Programming
    Replies: 9
    Last Post: 09-12-2005, 01:04 AM
  5. Bin packing problem....
    By 81N4RY_DR460N in forum C++ Programming
    Replies: 0
    Last Post: 08-01-2005, 05:20 AM