Click here to Skip to main content
15,920,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am developing WIndow Application with C# for log in form and like to know how can I do that.
ANY Example available over net.

please help.

Vijay
Posted

Create 2 lable controland text box Uname and password and 2 command button names are (1) btnlogin and (2) btnCancel

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Security.Cryptography;


namespace Test
{
    public partial class Log_In : Form
    {
        public Log_In()
        {
            InitializeComponent();
        }

              private void btnlogin_Click(object sender, EventArgs e)
        {
          if (txtUname.Text == ("Admin"))
            {
                if (TxtPassword.Text == ("QRSV"))
                {
                    Addapt a = new Addapt();
                    a.Show();
                }
          }
        }

        
        private void btnCancel_Click(object sender, EventArgs e)
        {
        Close();

        }
    }
}
 
Share this answer
 
 
Share this answer
 
1) Create your log in form as a separate class, derived from Form: call it frmLogin or similar.
2) Create an instance in your main Form Load event.
3) Show the login form as a modal dialog.
4) Check the users responses to ensure his user details are ok.

bool loggedIn = false;
while (!loggedIn)
   {
   frmLogin f = new frmLogin();
   if (frmLogin.ShowDialog == DialogResult.Cancel)
      {
      Close();
      return;
      }
   if (IsGoodLogin(f.UserName, f.Password))
      {
      loggedIn = true;
      }
   }
Then all you have to do is write IsGoodLogin - I can't help as I don't know anything about how you store names and passwords. However there is a note on password storage here: Password Storage: How to do it.[^]
 
Share this answer
 
Comments
Monjurul Habib 18-Jun-11 3:30am    
nice link , my 5.
Try this
Login Form for Windows Application[^]

Also check other answers in that page.
 
Share this answer
 
v4
Comments
thatraja 17-Jun-11 14:18pm    
There is no link man, update your answer.
divesh12 17-Jun-11 14:19pm    
yeah updated
thatraja 17-Jun-11 14:24pm    
OK fine, Take a 5!
divesh12 17-Jun-11 14:28pm    
thanks
Monjurul Habib 18-Jun-11 3:30am    
nice link , my 5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900