Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
How can I create a login form where the user credentials are stored in a database. I want to program this in C#.
Can anyone help me get started?

Thanks for your time!
Posted
Updated 14-Feb-12 5:09am
v2
Comments
Herman<T>.Instance 14-Feb-12 10:58am    
what is itching? What is your exact problem?
krumia 15-Feb-12 3:21am    
Can't you seeeee? "Can anyone help me get started?"... He has no clue! And he's too lazy to Google it. Why should anyone Google? Codeproject is there!
Manfred Rudolf Bihy 14-Feb-12 11:11am    
Please tag this question correctly. We don't know as of yet what kind of application you are planning.
Is it a "Windows Forms" application or a ASP.NET application.

Please tag your question appropriately! Thanks for your cooperation.
Shahin Khorshidnia 14-Feb-12 11:12am    
It's realy not clear.
What did you find about it? And what's the snag?

Here's some code I used, works perfect for me!
I'm using Microsoft Access 2007 and Visual Studio 2010 Ultimate on Windows 7 Ultimate x64.

You'll need to change the connection string and path to the actual database file

Code:
Add this in your Using Section:
using System.Data.OleDb;

string ConnStr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=G:\\MedDesk\\Login.accdb;";
            OleDbConnection MyConn = new OleDbConnection(ConnStr);
            try
            {
                MyConn.Open();
                string StrCmd = "SELECT User, Pass FROM LoginTable WHERE User='"+user.Text + "' and Pass='" + pass.Password + "'";
                OleDbCommand Cmd = new OleDbCommand(StrCmd, MyConn); ;
                OleDbDataReader ObjReader = Cmd.ExecuteReader();
                if (ObjReader != null)
                {
                    new MainWindow().Show();
                }
                ObjReader.Close();
                MyConn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
 
Share this answer
 
v3
1) Add a new form to your project.
2) Add two labels, two textboxes, and two buttons.
3) Change the label texts to "Username" and "Password"
4) Change the textbox names to "tbUsername" and "tbPassword"
5) In the properties pane for the "tbPassword" textbox, set "UseSystemPasswordChar" to true
6) Change the two button names to "butOK" and "butCancel"
7) In the properties pane, set butOK.DialogResult to "OK" and butCancel.DialogResult to "Cancel"
8) Double click the OK button.

Show the form in your code in the usual way. If the DialogResult is OK, check the two text boxes against your database. If they are not the same, show the form again.
 
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