Name

global.PwdQuestionAnswerHelper

Description

No description available

Script

var PwdQuestionAnswerHelper = Class.create();
PwdQuestionAnswerHelper.prototype = {
  initialize: function() {},

  getQuestionsList: function(requestId, userId, verificationId, num_reset, num_enroll) {
      var lengthOfSHA_256 = 76;
      var isRequestInvalid = new SNC.PwdTrackingManager().isRequestInvalid(requestId);
      var enrolledQuestions = {
          "q_id": [],
          "q": [],
          "answerId": [],
          "answerHashType": []
      };
      if (isRequestInvalid) {
          var gr = new GlideAggregate('pwd_question');
          gr.addAggregate('COUNT');
          gr.query();
          if (gr.next()) {
              var questionsCount = gr.getAggregate('COUNT');
          }
          num_enroll = num_enroll > questionsCount ? questionsCount : num_enroll;
          var questions = [];
          var hash = 1;
          var j = 0;
          for (var i = 0; i < userId.length; i++)
              hash = hash + userId.charCodeAt(i);
          while (hash.toString().length < num_enroll) {
              hash = hash * hash;
          }
          var count = Math.pow(10, questionsCount.toString().length);
          while (j < num_enroll) {
              var num = (hash % count) % questionsCount;
              if (questions.indexOf(num) == -1) {
                  questions.push(num);
                  j++;
              }
              count = count + 1;
          }
          var gr_questions = new GlideRecord("pwd_question");
  		gr_questions.orderByDesc('sys_name');
          gr_questions.query();
          count = 0;
          while (gr_questions.next()) {
              if (questions.indexOf(count) != -1) {
                  enrolledQuestions.q_id.push(gr_questions.getValue("sys_id"));
                  enrolledQuestions.q.push(gr_questions.getValue("question_translated"));
                  enrolledQuestions.answerHashType.push("SHA-256");
              }
              count++;
          }
      } else {
          var gr_answers = new GlideRecord('pwd_active_answer');
          gr_answers.addJoinQuery('pwd_enrollment', 'enrollment', 'sys_id');
          gr_answers.addQuery('enrollment.verification', verificationId);
          gr_answers.addQuery('enrollment.user', userId);
          gr_answers.query();
          while (gr_answers.next()) {
              enrolledQuestions.q_id.push(gr_answers.active_question.sys_id.toString());
              enrolledQuestions.q.push(gr_answers.active_question.question.toString());
              enrolledQuestions.answerId.push(gr_answers.sys_id.toString());
              enrolledQuestions.answerHashType.push(gr_answers.normalized_answer.toString().length < lengthOfSHA_256 ? "SHA-1" : "SHA-256");
          }
      }
      return enrolledQuestions;
  },

  type: 'PwdQuestionAnswerHelper'
};

Sys ID

6c1b528f5352011026b0ddeeff7b1280

Offical Documentation

Official Docs: