Solved

Accessing Database - Login System C#

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
About delegates in c sharp 3 47
Error when loading the database 16 64
designing in object programming 12 75
HttpPostedFile 1 26
Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

816 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

13 Experts available now in Live!

Get 1:1 Help Now