locked
Login RRS feed

  • Question

  • I want to  create login form in c#.net 

    Like 

    User Name,Password that details can be stored to sql server in that databse we create one login form . If i entered login details that can bel check database if that details are correct then login and show next window form ,if login details are false then show incorrect details.

    Wednesday, August 22, 2012 11:56 AM

Answers

  • create the following:

    simple table in the db having these columns:

    id int, auto increment

    username (45) nvarchar

    pass (15) nvarchar

    Then create the following stored procedures:

    sp_create_user

    {

      @username (45) nvarchar

    , @pass (15) nvarchar

    }

    insert into tb_users (@username, @pass);

    sp_check_user

    {

      @username (45) nvarchar

    , @pass (15) nvarchar

    }

    return (count tb_users where (username=@username) and (pass= @pass));

    in your code application create a form with 2 panels.

    First panel contain 2 textbox and a button use them to call the new user procedure.

    the second panel has 2 textbox, a button, and a label. use the label to show the result of the using of the search user procedure.

    I know I did not write in details, BUT as long as you made it to this portal you have to have some programming knowledge. You have to do your home work amigo


    Walid Elsayed

    • Proposed as answer by Lisa Zhu Thursday, August 23, 2012 2:36 AM
    • Marked as answer by Lisa Zhu Thursday, August 30, 2012 3:42 AM
    Wednesday, August 22, 2012 12:23 PM
  • You can do like this, for example.
                OdbcConnection con = new OdbcConnection("Driver={YOURDRIVER};server=localhost;uid=root;pwd=;database=test");
                using (con)
                {
                    con.Open();
                    using (OdbcCommand cmd = new OdbcCommand("SELECT COUNT(*) FROM t WHERE user =@a and pass =@b", con))
                    {
                        cmd.Parameters.AddWithValue("@a", textboxUser.Text);
                        cmd.Parameters.AddWithValue("@b", textboxPass.Text);
                        int verify = cmd.ExecuteNonQuery();
                        if(verify == 1)
                            // your login is valid
                        else
                            // bad login, error msg here.
    
                    }
                }
    There are millions of ways to do that. I'd recommend you make a search on google, you'll find helpful stuff to start.

    Web Developer

    • Proposed as answer by Lisa Zhu Thursday, August 23, 2012 2:36 AM
    • Marked as answer by Lisa Zhu Thursday, August 30, 2012 3:42 AM
    Wednesday, August 22, 2012 12:11 PM

All replies

  • Here are some links to start with:

    http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/baa85c20-7f6a-4c92-9917-24b6fa39ca67/

    http://rixxtech.blogspot.co.il/2011/01/how-to-create-login-form-in-c.html

     

    Noam B.



    Do not Forget to Vote as Answer/Helpful, please. It encourages us to help you...

    Wednesday, August 22, 2012 12:06 PM
  • You can do like this, for example.
                OdbcConnection con = new OdbcConnection("Driver={YOURDRIVER};server=localhost;uid=root;pwd=;database=test");
                using (con)
                {
                    con.Open();
                    using (OdbcCommand cmd = new OdbcCommand("SELECT COUNT(*) FROM t WHERE user =@a and pass =@b", con))
                    {
                        cmd.Parameters.AddWithValue("@a", textboxUser.Text);
                        cmd.Parameters.AddWithValue("@b", textboxPass.Text);
                        int verify = cmd.ExecuteNonQuery();
                        if(verify == 1)
                            // your login is valid
                        else
                            // bad login, error msg here.
    
                    }
                }
    There are millions of ways to do that. I'd recommend you make a search on google, you'll find helpful stuff to start.

    Web Developer

    • Proposed as answer by Lisa Zhu Thursday, August 23, 2012 2:36 AM
    • Marked as answer by Lisa Zhu Thursday, August 30, 2012 3:42 AM
    Wednesday, August 22, 2012 12:11 PM
  • create the following:

    simple table in the db having these columns:

    id int, auto increment

    username (45) nvarchar

    pass (15) nvarchar

    Then create the following stored procedures:

    sp_create_user

    {

      @username (45) nvarchar

    , @pass (15) nvarchar

    }

    insert into tb_users (@username, @pass);

    sp_check_user

    {

      @username (45) nvarchar

    , @pass (15) nvarchar

    }

    return (count tb_users where (username=@username) and (pass= @pass));

    in your code application create a form with 2 panels.

    First panel contain 2 textbox and a button use them to call the new user procedure.

    the second panel has 2 textbox, a button, and a label. use the label to show the result of the using of the search user procedure.

    I know I did not write in details, BUT as long as you made it to this portal you have to have some programming knowledge. You have to do your home work amigo


    Walid Elsayed

    • Proposed as answer by Lisa Zhu Thursday, August 23, 2012 2:36 AM
    • Marked as answer by Lisa Zhu Thursday, August 30, 2012 3:42 AM
    Wednesday, August 22, 2012 12:23 PM