Solved

User Login form

Posted on 2004-09-14
8
186 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
  • 4
  • 4
8 Comments
 
LVL 5

Expert Comment

by:tzxie2000
Comment Utility
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
Comment Utility
The code seems rather vague... do you think you could elaborate a bit more please?
0
 
LVL 1

Author Comment

by:reclusive
Comment Utility
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
 
LVL 5

Expert Comment

by:tzxie2000
Comment Utility
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 1

Author Comment

by:reclusive
Comment Utility
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
Comment Utility
yes
0
 
LVL 1

Author Comment

by:reclusive
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Article by: Ivo
Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

771 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