Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Password login screen

since1984since1984 Member Posts: 7
Hi im total new to builder c++
can you help me
i need to create a login screen that will ask for password and when right password entered it will send me to a new form(blank for the moment)

Comments

  • since1984since1984 Member Posts: 7
    if(Edit1->Text=="3")
    {
    Edit2->Text="hello";
    }
    MessageBox(NULL,"Wrong Password","Waring",MB_OK);

    this is what i got till now
    when the password is correct i want to close the current form (login screen) and open new blank form
  • SkyterrorSkyterror Member Posts: 16
    I assumed that you know the basic of events and can create other form in your application (Multiple Forms)

    For this sample, you must use 2 forms. first we call [color=Red]Form[/color]1 and other we call [color=Red]Form2[/color]. Form1 is the main form for your application and Form2 is your login screen.
    In Form2 we have a [color=Red]Label1[/color] which is a TLabel variable. That label has a text for asking user's password. We also have a [color=Red]Edit1[/color] which is a TEdit variable. It will store password that user entered. And next we have a [color=Red]Button1[/color] which is a TButton variable. We use this button to send a confirmation to program that user have done typing his password :)

    ----------
    First, include the header of Form2 in Form1. We must do it to let Form1 know that there is

    #include "Form2.h" // This is for example

    then, write down this code to OnCreate Method of 1st form
    void __fastcall TForm1::FormCreate(TObject *Sender)
    {
    TForm2* Form2 = new TForm2(Application) // We create instance of form2
    Form1->Hide(); // This will hide your main form for a moment
    Form2->ShowModal(); // This will display your child / 2nd form
    Form2->Hide();
    delete Form2;
    Form1->Show();
    }

    ----------
    write down this code to your OnClick method of Button1
    void __fastcall TForm2::Button1Click(TObject *Sender)
    {
    /*
    First we compare the text in Edit1 with our password.
    If both are match, then form2 will close and program will open form1. But if it's not it will prompt that user have enterd wrong password
    */
    if(Edit1->Text == "YourPaswordHere") // Any password you want :)
    {
    Form2->Close
    }
    else {
    MessageBox(Application->Handle, "You have entered wrong password", "Error", MB_ICONERROR);
    }
    }


    ----------
    write down this code to OnClose method of Form2
    void __fastcall TForm2::FormClose(TObject *Sender, TCloseAction &Action)
    {
    /*
    This will close application if user click the "x" button on upper-right of Form2 form. If we don't this, everytime user click thos close button, program will load the main form :(
    */
    Application->Terminate();
    }




    Now, we have donw writing our login-screen program :)I assumed that you know the basic of events and can create other form in your application (Multiple Forms)

    For this sample, you must use 2 forms. first we call [color=Red]Form[/color]1 and other we call [color=Red]Form2[/color]. Form1 is the main form for your application and Form2 is your login screen.
    In Form2 we have a [color=Red]Label1[/color] which is a TLabel variable. That label has a text for asking user's password. We also have a [color=Red]Edit1[/color] which is a TEdit variable. It will store password that user entered. And next we have a [color=Red]Button1[/color] which is a TButton variable. We use this button to send a confirmation to program that user have done typing his password :)

    ----------
    First, include the header of Form2 in Form1. We must do it to let Form1 know that there is

    #include "Form2.h" // This is for example

    then, write down this code to OnCreate Method of 1st form
    void __fastcall TForm1::FormCreate(TObject *Sender)
    {
    TForm2* Form2 = new TForm2(Application) // We create instance of form2
    Form1->Hide(); // This will hide your main form for a moment
    Form2->ShowModal(); // This will display your child / 2nd form
    Form2->Hide();
    delete Form2;
    Form1->Show();
    }

    ----------
    write down this code to your OnClick method of Button1
    void __fastcall TForm2::Button1Click(TObject *Sender)
    {
    /*
    First we compare the text in Edit1 with our password.
    If both are match, then form2 will close and program will open form1. But if it's not it will prompt that user have enterd wrong password
    */
    if(Edit1->Text == "YourPaswordHere") // Any password you want :)
    {
    Form2->Close
    }
    else {
    MessageBox(Application->Handle, "You have entered wrong password", "Error", MB_ICONERROR);
    }
    }


    ----------
    write down this code to OnClose method of Form2
    void __fastcall TForm2::FormClose(TObject *Sender, TCloseAction &Action)
    {
    /*
    This will close application if user click the "x" button on upper-right of Form2 form. If we don't this, everytime user click thos close button, program will load the main form :(
    */
    Application->Terminate();
    }




    Now, we have done writing our login-screen program :)
Sign In or Register to comment.