How to hash mobile number in CustomSMS Activity?


I am currently able to use CustomSMS activity to generate OTP and forward it to sms gateway using below script.  But this script displays mobile number in full in the Password Manager User Self Service portal under Generate OTP option e.g. +123456789.  I would like to mask the middle few numbers e.g. +123***789.  Here is the script.  I tried to play around the #TODO section but did not achieve expected result.

Can anyone help?



function PostLoad($workflow, $activity)
#Edit this list to specify additional attributes that can contain phone numbers
$PHONE_NUMBER_ATTRS = [string[]] ("telephoneNumber", "homePhone", "mobile")

#Obtain user's phone numbers
$user = $global.GetUserById($workflow.UserInfo.Domain, $workflow.UserInfo.Id, $PHONE_NUMBER_ATTRS)

if ($user -eq $null) {
$workflow.CriticalError([QPM.Common.Scenarios.WorkflowErrorCode]::SystemError, "User not found")
} else {
#Populate "Select phone number" combobox with phone numbers
$i = 0
$num = $user[$_]

#TODO: if necessary, mask and/or validate user's phone number
#Currently, any non-empty number will go
if ("$num" -ne "") {
$num = $num.ToString()
$activity.CustomData["PhoneNumber_$i"] = $num
$activity.Runtime.Controls["ddlPhoneNumber"].Options.Add("PhoneNumber_$i", $num)
$i = $i + 1
if ($i -eq 0) {
#No phone numbers could be used for authentication

function PreExecuting($workflow, $activity)

$phoneNumber= $activity.Runtime.Controls["ddlPhoneNumber"].Text
if ("$phoneNumber" -eq "") {
#Very unlikely - user not selected a phone number
$workflow.ActivityFailure("Please select a phone number")

#Edit this line to specify SMS gateway e-mail address where PIN code will be sent
#$MAIL = "$($phoneNumber)"
#For test purposes, PIN code will be sent to user's e-mail address
$MAIL = $workflow.UserInfo.AccountInfo.Mail

#TODO: specify passcode length here
$code = $global.GeneratePasscode(8)

$workflow.CustomData["PhoneAuthentication_Passcode"] = $code

#Sending a PIN code
$global.EmailUser($MAIL, "PIN code", $code)




Note: I have very basic knowledge in PS scripting or any other scripting.