Solved

Accessing Database - Login System C#

Posted on 2006-10-31
5
934 Views
Last Modified: 2008-02-01
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
Comment
Question by:angus_young_acdc
  • 3
5 Comments
 
LVL 29

Accepted Solution

by:
Gautham Janardhan earned 50 total points
ID: 17857663
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
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 17857672
//  new SqlConnection(""); instead of this

 new SqlConnection(urconnectionstring);
0
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 17857678
and also after
System.Data.SqlClient.SqlConnection Connection = new SqlConnection("");
Connection.Open()
0
 
LVL 15

Author Comment

by:angus_young_acdc
ID: 17865048
Thanks gauthampj, I will try it shortly and let you know
0

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

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video discusses moving either the default database or any database to a new volume.

744 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

12 Experts available now in Live!

Get 1:1 Help Now