C # locking an account on a specified computer only

Source: Internet
Author: User

Add a field mac in the database to write mac information or IP information of the corresponding user to this field. Use the following code to bind the account to the computer!
Using System. Security. Cryptography;) must be added to the md5 encryption password in red ;):
String username = tb_username.Text.ToString (). Trim ();
// Byte [] result = Encoding. Default. GetBytes (this. tb_password.Text.Trim ());
// MD5 = new MD5CryptoServiceProvider ();
// Byte [] output = md5.ComputeHash (result );
// String userpass = BitConverter. ToString (output). Replace ("-","");
String userpass = tb_password.Text.ToString (). Trim ();
String SQL = "select id, username, userpass, mac from p_users where username = '" + username + "' and userpass = '" + userpass + "'";
SqlCommand cmd = new SqlCommand (SQL, conn );
Try
{
Conn. Open ();
SqlDataReader dr = cmd. ExecuteReader ();
If (dr. Read ())
{
String mac = getMacAddr_Local (); // string ip = GetIP (); if (mac! = Dr ["mac"]. ToString ())
{
MessageBox. Show ("Please use this program on the Right computer! ");
Application. Exit ();
}
Else
{
Id = dr ["id"]. ToString ();
// Name = dr ["truename"]. ToString ();
// Userrole = dr ["userrole"]. ToString ();
This. Close ();
}}
Else
{
MessageBox. Show ("incorrect user name or password! "," Error ", MessageBoxButtons. OK );
}
}
Catch (Exception ex)
{
Ex. ToString ();
}
Finally
{
Conn. Close ();
}


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.