Skip to content

AddQuestion()

ts
AddQuestion(pos: number, q: string, a: string, echo: boolean): void;

Adds a custom question with a precise pre-defined answer to the list of questions that will be asked during keyboard-interactive authentication.

CAUTION

This function MUST only be used inside an OnAuthInteractiveSetQuestions event-handler.

The parameters are as follows:

ParameterTypeExplanation
posnumberThe question's zero-based position; when, in the sequence, this question should be asked
qstringThe question (MUST end with a colon :)
astringThe pre-defined expected (correct) answer
echobooleanWhether or not the answer should be echoed back to the client (hint: passwords/secrets should not)

Example

ts
{
  if (Session) {
    // First, ask for the user's password
    Session.AddQuestionPassword(0, 'Type your password:');
    // Next, ask for Google Authenticator OTP (for 2FA/MFA)
    Session.AddQuestionTOTP(1, 'Type your Authenticator OTP:');
    // Then ask for any question we want
    Session.AddQuestion(2, 'Life, the Universe and Everything:', '42', true);
  } else {
    Log('Session object is not available.');
  }
}