Click here to Skip to main content
15,885,669 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to create form Login with:
- textboxUserName
- textboxPassword
- buttonLogin

My database have decentralization user table

if the username is admin, then open form 1
if the username is the user opens the form 2

Please help me, thank
Posted
Comments
Mahesh Bailwal 18-Jun-13 3:32am    
Are you facing any problem in doing it.?

Step 1) Create a new form
Step 2) Add 2 text boxes
Step 3) Add a Login button
Step 4) Write a method to authenticate users
Step 5) Open appropriate form

Note a) I would suggest using a password box, or a masked text box for the password box so that it is not in plain text for the world to see.

Note b) In future try something, do some research, don't expect a solution to something when it appears you have tried nothing.
 
Share this answer
 
This is my code with not decentralization users
C#
try
 {
     if (txtUserName.Text == "" || txtPassword.Text == "")
     {
         MessageBox.Show("Entry Username and Password", "Error");
         txtUserName.Focus();
         return;
     }
     else
     {
         SqlConnection conn = new SqlConnection(@"Data Source=; Initial Catalog=; uid = sa; pwd = 123456;");
         conn.Open();
         SqlCommand cmd = new SqlCommand("Select Pass From Account Where UserName ='" + txtUserName.Text + "'", conn);
         SqlDataReader reader = cmd.ExecuteReader();
         reader.Read();
         if (txtPassword.Text == reader.GetValue(0).ToString())
         {
             MessageBox.Show("Login success!", "Success");
             reader.Close();
             conn.Close();
             this.Hide();
             Form2 frm2 = new Form2();
             frm2.ShowDialog();
         }
         else
         {
             MessageBox.Show("Wrong password", "Error");
             txtPassword.Focus();
         }
         reader.Close();
         conn.Close();
     }
 }
 catch (Exception)
 {
     MessageBox.Show("Wrong Username or Password", "Error");
     txtUserName.Focus();
 }
 
Share this answer
 
Comments
Pheonyx 18-Jun-13 3:54am    
a) What do you mean by "decentralization users" ?
b) That code is very susceptible to SQL Injection
c) Are you storing your password in plain text because there is no hashing/encryption going on there?!
Nguyễn Quang Nghĩa 18-Jun-13 4:12am    
a) Decentralization users: Ex Admin, Mod, user
c) I do not need to encrypt passwords
Pheonyx 18-Jun-13 4:21am    
a) Decentralization users: Ex Admin, Mod, user << that doesn't mean anything to me... explain what it is.. do you have multiple tables? One with Admin's in, one with Mods in, one with Users in?
Do you have a users table, and a groups table?
C#
if (txtPassword.Text == reader.GetValue(0).ToString())
               {
                   MessageBox.Show("Login success!", "Success");
                   reader.Close();
                   conn.Close();
                   this.Hide();
                   //I need assistance in this paragraph
                   //if (user == admin) open form 1
                   // else open form 2
               }
 
Share this answer
 

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