1. authentication method for user identity and permissions;
Public String myusercheck (string txt_username, string txt_password)
{
String sqlcmdtxt, usersort;
Usersort = "nobody ";
Sqlcmdtxt = "select userid, userpassword, usersort from [user]";
Sqlcommand mysqlcmd = new sqlcommand (sqlcmdtxt, this. mylibrayconnection );
Try
{
This. mylibrayconnection. open ();
Sqldatareader mysqldatareader = mysqlcmd. executereader ();
While (mysqldatareader. Read ())
{
If (mysqldatareader [0]. tostring (). Trim () = txt_username) & (mysqldatareader [1]. tostring (). Trim () = txt_password ))
{
Usersort = mysqldatareader [2]. tostring (). Trim ();
Break;
}
}
}
Catch (exception E)
{
MessageBox. Show (E. tostring ());
}
This. mylibrayconnection. Close ();
Return usersort;
}
Note: 1. Use the sqldatareader object and judge the data in the sqldatareader object one by one.
2. Because user is a system keyword, if the user-defined table name is used, you need to add [] to indicate that it is a user-defined table rather than a system keyword;
2. Determine the button method.
Private void btnok_click (Object sender, system. eventargs E)
{
If (myusercheck (this. textuserid. text, this. textuserpassword. Text) = "system ")
{
This. Visible = false;
Form mainform = new mainform (this. textuserid. Text, "system ");
Mainform. showdialog ();
This. Close ();
}
Else if (myusercheck (this. textuserid. text, this. textuserpassword. Text) = "user ")
{
This. Visible = false;
Form mainform = new mainform (this. textuserid. Text, "user ");
Mainform. showdialog ();
This. Close ();
}
Else
{
If (MessageBox. Show ("incorrect user password, re-login", "Incorrect", messageboxbuttons. okcancel, messageboxicon. Question) = dialogresult. OK)
{
This. textuserid. Clear ();
This. textuserpassword. Clear ();
// This. textuserid .();
}
Else
{
This. Close ();
}
}
}
Note: 1. Use the "user identity and permission verification method" to return the user's permission string from the database and compare it to go to the relevant permission page.