Skip to main content

One Time Password

One time password (OTP) is a password that is valid for only one login session or transaction, on a computer system or other digital device. It is also known as a one-time PIN or dynamic password. You can configure the OTP delivery method in the admin portal. It can be delivered through email, SMS or voice call.

caution

This sample is for demonstration purposes only. It is not intended for production use. In production, you should use a secure method to store the application id.

Prerequisites

To enable OTP authentication, users must have a valid email address or mobile number.

Authentication

To authenticate a user with OTP, see the following sample code.

package com.entrust.idaas.userAuthenticate;

import com.entrustdatacard.intellitrust.auth.ApiClient;
import com.entrustdatacard.intellitrust.auth.api.AuthenticationApi;
import com.entrustdatacard.intellitrust.auth.model.*;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class UserAuthenticate {
private static final String APPLICATION_ID = "YOUR_APPLICATION_ID";
private static final String HOST_NAME = "YOUR_HOST_NAME";

public static void main(String args[]) throws Exception {
ApiClient apiClient = new ApiClient();
apiClient.setBasePath(HOST_NAME);
AuthenticationApi authApi = new AuthenticationApi(apiClient);

String userId = "exampleUser"
String authType = "OTP";

UserChallengeParameters userChallengeParameters = new UserChallengeParameters()
.applicationId(APPLICATION_ID)
.userId(userId)
.otpDeliveryType(UserChallengeParameters.OtpDeliveryTypeEnum.EMAIL);

AuthenticatedResponse challengeResponse = authApi.userChallengeUsingPOST(authType, userChallengeParameters);

System.out.print("Enter response: ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String response = br.readLine();

UserAuthenticateParameters userAuthenticateParameters = new UserAuthenticateParameters()
.applicationId(APPLICATION_ID)
.response(response);

try {
AuthenticatedResponse authenticatedResponse = authApi.userAuthenticateUsingPOST(authType, userAuthenticateParameters, challengeResponse.getToken()); if (Boolean.TRUE.equals(authenticatedResponse.getAuthenticationCompleted())) {
System.out.println("Authentication successful");
}
} catch (Exception e) {
System.out.println(e.getMessage());
System.out.println("Authentication failed");
}
}
}