Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SAP Sybase SQL Anywhere 16.0 » MobiLink - Getting Started » MobiLink tutorials » Tutorial: Using Java or .NET for custom user authentication

 

Lesson 1: Creating a .NET class for custom authentication (server-side)

In this lesson, you compile a class containing .NET logic for custom authentication.

Prérequis

The MobiLink server must have access to the classes in iAnywhere.MobiLink.Script.dll to execute .NET synchronization logic. iAnywhere.MobiLink.Script.dll contains a repository of MobiLink .NET server API classes to utilize in your .NET methods. When you compile your .NET class, you reference iAnywhere.MobiLink.Script.dll.

This lesson assumes that you have the roles and privileges listed in the Privileges section at the start of this tutorial: Tutorial: Using Java or .NET for custom user authentication.

Contexte et remarques

To create a .NET class for customer authentication, see Lesson 1: Creating a Java class for custom authentication (server-side).

 Task
  1. Create a class named MobiLinkAuth and write an authenticateUser method.

    The MobiLinkAuth class includes the authenticateUser method used for the authenticate_user synchronization event. The authenticate_user event provides parameters for the user and password. You return the authentication result in the authentication_status inout parameter.

    Note

    You register the authenticateUser method for the authenticate_user synchronization event in Lesson 2: Registering your Java or .NET scripts for the authenticate_user event.

    Use the following code for your server application:



    using iAnywhere.MobiLink.Script;
    
    public class MobiLinkAuth {
        public void authenticateUser(
            ref int authentication_status,
            string user,
            string pwd,
            string newPwd ) {
    
            if(user.StartsWith("128")) {
                // success: an auth status code of 1000
                authentication_status = 1000;
            } else { 
                // fail: and authentication_status code of 4000
                authentication_status = 4000;
            }
        }
    }

    This code illustrates a simple case of custom user authentication. Authentication succeeds when the client accesses the consolidated database using a user name that starts with 128.

  2. Save your code.

    This tutorial assumes c:\MLauth as the working directory for server-side components. Save the file as MobiLinkAuth.cs in this directory.

  3. Compile your class file.

    1. Navigate to the directory that contains your C# file.

    2. Compile the MobiLinkAuth class and refer to the MobiLink server .NET API library.

      Run the following command, replacing C:\Program Files\SQL Anywhere 16\ with your SQL Anywhere 16 directory:

      csc /out:MobiLinkAuth.dll /target:library /reference:"C:\Program Files\SQL Anywhere 16\Assembly\v2\iAnywhere.MobiLink.Script.dll" MobiLinkAuth.cs

Résultat

The MobiLinkAuth.dll assembly is generated.

 See also