C # How to sign up for the sharing software, registered users and so on network authorization authentication

Source: Internet
Author: User

In C # to develop shareware, the traditional use of registration code verification method, which is the way most of the sharing software adopted, there is a common authentication method, is through the network authorization authentication method, this way by invoking the Server service in the program. Generally has the authentication user name to be available, registers the new user, the user login authentication, the user changes the password and so on operation, also needs to be equipped with a network authorization entrance to the administrator to the registered user Authorization control.

This is for the network authorization to build a simple management background, the user in the shared software client through the call Server service connection, you can register a new user, or login to obtain identity information (trial, registered, disabled, etc.), but also through the service Interface for password modification, Improve safety and use rationality.

Network authentication has several advantages, one can not be limited to the traditional machine code restrictions, can be used in multiple computers, and the second is to facilitate the software developers to centrally manage user information, dynamic authorization or cancellation of authorized user identity information, but also to obtain more users of information, in order to promote communication.

When you develop a network authorization business background, you need to create a service interface to make calls to the software client, which can be processed by creating a handler such as ASHX, which is a little different from the ASPX page processing, which provides more raw output and what it needs to output.

This is for the network authorization to build a simple management background, the user in the shared software client through the call Server service connection, you can register a new user, or login to obtain identity information (trial, registered, disabled, etc.), but also through the service Interface for password modification, Improve safety and use rationality.

Network authentication has several advantages, one can not be limited to the traditional machine code restrictions, can be used in multiple computers, and the second is to facilitate the software developers to centrally manage user information, dynamic authorization or cancellation of authorized user identity information, but also to obtain more users of information, in order to promote communication.

When you develop a network authorization business background, you need to create a service interface to make calls to the software client, which can be processed by creating a handler such as ASHX, which is a little different from the ASPX page processing, which provides more raw output and what it needs to output.
This processing page, like the traditional ASPX page, accepts parameters like Test.aspx?id=1&name=test, and its processing code is shown below.
Copy Code

<summary>///user test Account availability, registration of new users, login verification, change password and other Operations business processing class///</summary>[webservice (Namespace = "http:// tempuri.org/")][webservicebinding (ConformsTo = wsiprofiles.basicprofile1_1)]public class useraction:ihttphandler{ Public    void ProcessRequest (HttpContext context)    {        //context. Response.ContentType = "Text/plain";        Context. Response.Write ("Hello World");        Context. request.contentencoding = Encoding.default;        String action = context. Request["Action"];        String usr = context. request["usr"];        String Password = context. Request["Pass"];        String Machinecode = context. request["Code"];

Copy Code

By getting the contents of the parameters, we can do different business processing, here I use a flag of action, to distinguish what is done.
Copy Code

String action = context. Request["Action"];        String usr = context. request["usr"];        String Password = context. Request["Pass"];        String Machinecode = context. request["Code"];        BOOL result = FALSE;        Switch (action)        {case            "R"://Detect registration Useraction.ashx?action=r&usr=&pass=&code=                String reg = Bllfactory<softwareregister>. Instance.checkregisterd (usr, password, machinecode);                Context. Response.ContentType = "Text/plain";                Context. Response.Write (reg);                Break

Copy Code

The above is to perform a detection of whether the user is registered operation code, if the authorization is registered, returns True, if the user logon succeeds but no authorization, return false, other errors return a string description. Specific to
Bllfactory. The Instance.checkregisterd logic processing code is shown below.
Copy Code

public string Checkregisterd (string username, string Passwod, string code) {BOOL result = Verifyuser (username,        PASSWOD, code); if (result) {string condition = string.            Format ("Username= ' {0} ' and Isforbid <> true", Username); Softwareregisterinfo info = base.            Findsingle (condition); if (info! = null) {if (info. Isregister) {if (info). Machinecode! = Code && info. Lastaccessed.addminutes (>= datetime.now) {return "login multiple places in one account!"                    "; } else {info.                        Machinecode = code; Info.                        lastaccessed = DateTime.Now; Base. Update (info, info.id.                        ToString ());                    Return "true"; }} else {                   Return "false";            }} else {return ' account is locked ';        }} else {return ' account password is incorrect '; }    }

Copy Code

So how do we verify the identity of the user in the place where the software is shared, by passing the page parameters and calling the Ashx interface processing to determine the return value. The specific operation code is shown below. To simplify the operation, a library of my common classes was used to submit the data (helper class Httphelper).
Copy Code

private void Btnok_click (object sender, EventArgs e) {if (this.txtUserName.Text.Length = = 0) {            Messageexutil.showtips ("Please Enter account password login");        Return } string data = String. Format ("Action=r&usr={0}&pass={1}&code={2}", This.txtUserName.Text, This.txtPassword.Text, WHC.        OrderWater.Commons.HardwareInfoHelper.GetMacAddress ());        Httphelper helper = new Httphelper (); string result = Helper.        Gethtml (PORTAL.GC.USERACTIONURL, data, true); if (!string. IsNullOrEmpty (Result)) {if (result).                ToLower () = = "true") {Portal.gc.UserName = This.txtUserName.Text;                Portal.gc.Registered = true;                Messageexutil.showtips ("Login Successful"); This.            DialogResult = DialogResult.OK; } else if (result.                ToLower () = = "false") {Messageexutil.showtips ("unauthorized user, but may continue to use"); Portal.gc.UserName = This.txtusernAme.                Text;                Portal.gc.Registered = false; This.            DialogResult = DialogResult.OK;            } else {messageexutil.showtips ("operation failed:" + result);        }} else {messageexutil.showtips ("operation failed"); }    }

Copy Code

Above is a complete implementation of the function of the process, the other functions are similar operations, the following gives the complete code for ASHX implementation, for your reference, and correct.
Copy Code

<summary>///user test Account availability, registration of new users, login verification, change password and other Operations business processing class///</summary>[webservice (Namespace = "http://    tempuri.org/")][webservicebinding (ConformsTo = wsiprofiles.basicprofile1_1)]public class useraction:ihttphandler{ public void ProcessRequest (HttpContext context) {//context.        Response.ContentType = "Text/plain"; Context.        Response.Write ("Hello World"); Context.        request.contentencoding = Encoding.default; String action = context.        Request["Action"]; String usr = context.        request["USR"]; String Password = context.        Request["Pass"]; String Machinecode = context.        request["Code"];        String conditon = "";        BOOL result = FALSE; Switch (action) {case "R"://Detect registration Useraction.ashx?action=r&usr=&pass=&code= s Tring reg = Bllfactory<softwareregister>.                Instance.checkregisterd (usr, password, machinecode); Context.                Response.ContentType = "Text/plain";Context.                Response.Write (REG);            Break Case "G"://Test Login useraction.ashx?action=g&usr=&pass=&code= result = Bllfactory<softwareregiste R>.                Instance.verifyuser (usr, password, machinecode); Context.                Response.ContentType = "Text/plain"; Context.                Response.Write (Result);            Break Case "T"://test user name useraction.ashx?action=t&usr= result = Bllfactory<softwareregister>.                Instance.isexistkey ("Username", usr); Context.                Response.ContentType = "Text/plain"; Context.            Response.Write (!result);//returns False if present, otherwise true break;  Case "a"://Add user useraction.ashx?action=a&usr=&pass=&sex=&code=&qq=&email= bool exist = Bllfactory<softwareregister>.                Instance.isexistkey ("Username", usr); if (!exist) {password = context.               Request["Pass"];     Machinecode = context.                    request["Code"]; string sex = Context.                                            request["Sex"]; String QQ = context.                    Request["QQ"]; string email = context. request["email"];

Softwareregisterinfo newinfo = new Softwareregisterinfo ();

Newinfo.username = usr;                    Newinfo.password = Md5util.getmd5_16 (Password);                    Newinfo.sex = Sex;                    Newinfo.machinecode = Machinecode;                    NEWINFO.QQ = QQ;                    Newinfo.email = Email; result = Bllfactory<softwareregister>.                Instance.insert (Newinfo); } context.                Response.ContentType = "Text/plain"; Context.                Response.Write (Result);            Break Case "EP"://Modify user password useraction.ashx?action=ep&usr=&pass=&newp= Conditon = string.                Format ("Username= ' {0} '", USR); Password = context.                Request["Pass"]; String newpass = context.                request["NEWP"]; Softwareregisterinfo info = bllfactory<softwareregister>.                Instance.findsingle (Conditon); if (info! = null) {if (md5util.getmd5_16 (password) = = info. Password) {                        Info.                        Password = Md5util.getmd5_16 (Newpass); result = Bllfactory<softwareregister>. Instance.update (info, info.id.                    ToString ()); }} context.                Response.ContentType = "Text/plain"; Context.                                    Response.Write (Result);        Break        }} public bool IsReusable {get {return false; }    }}

The code is finished writing

If you want to consider security, there may be a whole need to make some adjustments, but the specific operation, has achieved the functionality we need. But shared software development needs to be perfected.

C # How to sign up for the sharing software, registered users and so on network authorization authentication

Related Article

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.