User verifications

This article is a draft and is continuously being updated.

Instead of authenticating users using their license key, which was described in the key verification tutorial, you can authenticate them using their username and password. This can be preferred in the following use cases:

  1. When your customers have multiple licenses.
  2. When your service offers a web-version and a desktop version.

In case it is the first use case when customers have many licenses and you want to issue them one single license, please check out customer secret tutorial.

When you set up user authentication using Cryptolens, you can manage the entire process yourself from your backend, including creation of new users, restoring password, etc. Similar to key verification, your customers will not have to interact with Cryptolens dashboard and you have control over the entire user experience.

If you would prefer Cryptolens to manage the user experience, you can use the following approach instead.

Getting started

You can read more about all the methods that are available in the Web API documentation. The goal of this tutorial is to focus on the authentication method that retrieves all licenses that belong to a user.

To authenticate the user inside your application, we can use the code below. When Login method is called, it will return all the licenses that belong to your customer (assuming that the User is linked to a Customer in Cryptolens).

The code examples below require an access token with either UserAuthNormal or UserAuthAdmin permission. When running the code inside your application, please assign the access token UserAuthNormal permission only.

In C#, the following code could be used as an example:

var result = UserAuth.Login("access token with UserAuthNormal permission", new LoginUserModel { UserName = "username", Password = "password" });


if(!Helpers.IsSuccessful(result)) 
{ 
  // error
}

var license = result.LicenseKeys.FirstOrDefault(x => x.ProductId == 123);

if(license != null)
{
  // no license for the product found
}

// proceed with activation as usual (if you want to use node-locking etc).
Key.Activate("", new ActivateModel { ProductId = 123, Key = license.Key, MachineCode = Helpers.GetMachineCodePI(v: 2) });

In Python, the code is similar:

# res will be a tuple, where the first item contains the list of licenses or None.
res = User.login("access token with UserAuthNormal permission", "username","password")

if res == None:
  print("No licenses found")

# find the first license object that comes from product 123.
# if you want to obtain all licenses from product with id 123 (just an example), you 
# can use licenses = [obj for obj in res[0] if obj['productId'] == 123]
license = next((obj for obj in res[0] if obj['productId'] == 123), None)

if license != None:
  # extract the license key and call Key.activate as described in the key verification tutorial.