Solved

Accessing Database - Login System C#

Posted on 2006-10-31
5
935 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Image(7) 1 53
Different Delete Messages 7 37
DateTimepicker 4 33
In WPF / C# binding a local database in code behind 1 24
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
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, f…

863 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

26 Experts available now in Live!

Get 1:1 Help Now