Solved

User Login form

Posted on 2004-09-14
8
191 Views
Last Modified: 2010-04-15
I have a problem wher eI'm trying to create a user login form that connects to a SQL server DB backend and validates the user name and password... the username field on the form is a text box rather than a combo box to ensure added security hopefully...

Does anyone have an idea of how to go about this?
0
Comment
Question by:reclusive
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 5

Expert Comment

by:tzxie2000
ID: 12058805
how about

put user name and password in the form

write code in OK Click event

if (isOKConnection(username,password))
....
else
MessageBox.Show("error username or password");

private bool isOKConnection(string username,string password)
{
     
try
{
    string myConnectString = "Persist Security Info=False;Integrated  Security=SSPI;database=northwind;server=mySQLServer;Connect Timeout=30;username="+username+";password="+password;
    SqlConnection myConnection = new SqlConnection(myConnectString);
    myConnection.Open();
    myConnection.Close();
    return true;
 }
catch
{
}
return false;
}
0
 
LVL 1

Author Comment

by:reclusive
ID: 12059093
The code seems rather vague... do you think you could elaborate a bit more please?
0
 
LVL 1

Author Comment

by:reclusive
ID: 12059173
ERK! Maybe I was being ague in my explination lol...

I want to create a login form for my application to allow users to access it, not to access the database. The user inputs their username and password on the login form, and click the ok button. The form then opens a connection to the database and checks to see if the username and password match. If they do then allow access.. if not then deny access and +1 to a counter

Is that more explanitory? *grin*
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 5

Expert Comment

by:tzxie2000
ID: 12059263
put a odbcconnection and odbccommand on your form

design odbcconnection's connectionstring to your database
set odbccommand.connection to odbcconnection

write code in OK click even

odbcconnection.open
odbccommand.commandtext="select count(*) from userdb where username='"+username.text+"' and password='"+password.text+"'";//username and password is the textbox you provide to enter relate information
Int32 count = (int32) ExecuteScalar();
switch(count)
{
   case 0:
     MessageBox.Show("error username or password!") ;
     break;
   case 1:
     //check username and password is ok,doing what you want
     break;
  default:
     MessageBox.Show("error for multi username and password");
     break;
}
0
 
LVL 1

Author Comment

by:reclusive
ID: 12059348
if I change the ODBC to a SQL the principle will work the same right? Sorry for being really dumb about this, but I'm still learning C# *bluish*
0
 
LVL 5

Accepted Solution

by:
tzxie2000 earned 250 total points
ID: 12059384
yes
0
 
LVL 1

Author Comment

by:reclusive
ID: 12069025
Shot! You helped with 2 of me problems so far *grin* Out of curiosity how do you change the amount of points for an open question?
0
 
LVL 5

Expert Comment

by:tzxie2000
ID: 12070592
sorry I do not know about how to change the points.
Maybe you can get help from administrator
but could I ask a little question about why you give me Grad B and what answer could let you give Grad A?
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

707 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