Log In Form

Posted on 2006-03-22
Last Modified: 2010-04-16
hi there , in my App i made a Form that u log into the App whit .
the code is :

SqlCommand cmd1 = new SqlCommand();
                  SqlParameter parm = new SqlParameter("@parm",SqlDbType.VarChar,50,"Pass");
                  cmd1.CommandText = "select @parm = Pass from Bakara";
                  string Password = parm.Value.ToString();
                  if(Password == this.editBox1.Text)
                        MessageBox.Show("The Pass Is False try Agian");
                  if (i==3)
                        MessageBox.Show("Incoorect 3 time Piss Off");

now if the user close the form the app is still working whitout the login was verified to be true .
what can i do to overpower this problem ?
Question by:Tech_Men
    LVL 10

    Assisted Solution

    Use the event the app throws when it closes and put the text you need to close the connection on it
    LVL 21

    Accepted Solution

    there're really several approaches, some of them:

    your login form could be the application main form (my preference) - in other words, that's the one with the Main() function in it, in which case if you close this form, the whole application is closed.

    another way is you can just add OnClosing event handler for your login form and from there you can call some public function from your current main form which would call this.Close(); of your main form - it will close your main application

    if you WANT your user be able to see your application without logging but not be able to do anything, you can set a parameter parameter of your main application from your login form to true or false depending on the login situation and check for this parameter in your application form (in the form load method), then you can diable controls for example and show big message across your form - log in first please.

    good luck,
    LVL 85

    Assisted Solution

    by:Mike Tomlinson
    Set the DialogResult property of the login form before you exit.  Then you can check this back in the calling form to test whether or not login was successful and exit the application if appropriate.

    (When the close button is clicked on a modal form the DialogResult is set to Cancel for you)

    Simplified example:

                Form1 f1 = new Form1();
                if (f1.ShowDialog() != DialogResult.OK)

                // continue with your app...

        public partial class Form1 : Form

            private void button1_Click_1(object sender, EventArgs e)
                // set the DialogResult based on the results
                if (true)
                    this.DialogResult = DialogResult.OK;
                    this.DialogResult = DialogResult.Cancel;

    LVL 8

    Assisted Solution

    Here is my solution:

     static void Main(string[] args)
                   LoginForm login = new LoginForm();
                   if( login.IsOK == true )
                        Application.Run(new MainForm());

    IsOK is a property of LoginForm (or public variable). You must set login.IsOK == true if user and password are correct

    Good luck,

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
    This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now