reclusive
asked on
User Login form
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?
Does anyone have an idea of how to go about this?
ASKER
The code seems rather vague... do you think you could elaborate a bit more please?
ASKER
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*
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*
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="s elect count(*) from userdb where username='"+username.text+ "' and password='"+password.text+ "'";//user name 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;
}
design odbcconnection's connectionstring to your database
set odbccommand.connection to odbcconnection
write code in OK click even
odbcconnection.open
odbccommand.commandtext="s
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;
}
ASKER
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*
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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?
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?
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?
put user name and password in the form
write code in OK Click event
if (isOKConnection(username,p
....
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=nor
SqlConnection myConnection = new SqlConnection(myConnectStr
myConnection.Open();
myConnection.Close();
return true;
}
catch
{
}
return false;
}