• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 945
  • Last Modified:

Accessing Database - Login System C#

Hey guys,

I am trying to create a more secure login for my Windows App using Visual Studio 2005 C#.  I have a MS Access Database, which has the following collums:
UserName   Password

And these are the details inside:
username1  password1
username2 password2
username3 password3
etc

I have used a DataGridView to connect the database to the program, I am unsure if that's correct.  Anyway what I want to do is the user types their username, then password.  When they click Accept (button) then I want the program to check the database, see if the user name is correct with the right password, and then return whether it is correct or not.  

After that I think I should be able to handle the permissions side.  So can anybody help me out please?  I am not great with C# so will need it explain in idiot terms lol, with as much help with the code as possible.
0
angus_young_acdc
Asked:
angus_young_acdc
  • 3
1 Solution
 
Gautham JanardhanCommented:
strSql = string.Format("SELECT LOGINPWD FROM BT_USERS WHERE LOGINID ="
                              +" {0}",
                              clsCommon.quotedStr(txt_loginid.Text));
                        System.Data.SqlClient.SqlConnection Connection = new SqlConnection("");
                        System.Data.SqlClient.SqlCommand Command= new SqlCommand
                              (strSql,Connection);
                        SqlDataReader sql_dat_rdrLogin = Command.ExecuteReader();
                        if(sql_dat_rdrLogin.HasRows)
                        {
                              sql_dat_rdrLogin.Read();
                              if (sql_dat_rdrLogin[0].ToString() == txt_pwd.Text.Trim())
                              {
                                    //login
                              }
                              else
                              {
                                    MessageBox.Show("Password incorrect");
                                    txt_pwd.Focus();
                              }
                        }
                        else
                        {
                              MessageBox.Show("Username incorrect");
                              txt_loginid.Focus();
                        }
0
 
Gautham JanardhanCommented:
//  new SqlConnection(""); instead of this

 new SqlConnection(urconnectionstring);
0
 
Gautham JanardhanCommented:
and also after
System.Data.SqlClient.SqlConnection Connection = new SqlConnection("");
Connection.Open()
0
 
angus_young_acdcAuthor Commented:
Thanks gauthampj, I will try it shortly and let you know
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now