User identity and permission verification on the logon Interface

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.