!fnpw.bsi [101] - function(s) related to prompting for passwords
!------------------------------------------------------------------------
!EDIT HISTORY
!Version 1.0:-
! [101] 06-Sep-23 / jdm / add keywords (for sosfuncidx), notes
! [100] 23-Nov-20 / jdm / created
!------------------------------------------------------------------------
!REQUIREMENTS
!
!NOTES
!
!KEYWORDS: passwords dialog popup
!
!ALSO SEE:
!
!PUBLIC FUNCTIONS
!   Fn'Ask'Password(prog$, pw$, title$) - prompt for password in popup dialog
!------------------------------------------------------------------------

++ifnlbl Fn'Ask'Password()

++include'once ashinc:ashell.def
++include'once ashinc:types.def

!---------------------------------------------------------------------
!Function:
!   Ask for and check password
!Params:
!   pw$ (str) [in] - correct password (default is @!#YYMMDD*)
!   title$ (str) [in] - dialog title (defaults to program name)
!   prog$  (str) [in] - password key/category/program (default = program name)
!   
!Returns:
!   .TRUE or .FALSE
!Globals:
!Notes:
!   if Fn'Ask'Password(pw$="secret") then
!       <proceed>
!   else
!       <authentication failure>
!   endif   
!---------------------------------------------------------------------
Function Fn'Ask'Password(prog$=.PGMNAME as s16:inputonly, &
                         pw$="@!#"+.YYMMDD+"*" as s16:inputonly, &
                         title$=.PGMNAME as s40:inputonly) as BOOLEAN
    
    map1 locals
        map2 inxctl,f
        map2 exitcode,f
        map2 askpw$,s,16
        
    
    ! Based on prog$, and potentially .USERNAME, you might call a routine
    ! from here to retrieve the password from a file. (Left as an exercise
    ! for the developer)
    
    xcall AUI, AUI_CONTROL, CTLOP_ADD, "dlgPW", title$, MBST_CENTER, &
        MBF_DIALOG+MBF_SYSMENU, NUL_CMD$, NUL_FUNC$, NUL_CSTATUS, &
        1, 1, 4, 40, NUL_FGC, NUL_BGC, &
        NUL_FONTATTR, NUL_FONTSCALE, NUL_FONTFACE$, NUL_TOOLTIP$, &
        NUL_PARENTID, NUL_WINCLASS$, NUL_WINSTYLE, NUL_WINSTYLEX, &
        NUL_CTYPE2
    
    xcall AUI, AUI_CONTROL, CTLOP_ADD, "txtPW", "Enter Password:", MBST_ENABLE, &
        MBF_STATIC+MBF_LFJUST, NUL_CMD$, NUL_FUNC$, NUL_CSTATUS, &
        2, 3, 5, 20, NUL_FGC, NUL_BGC, &
        NUL_FONTATTR, 180, NUL_FONTFACE$, NUL_TOOLTIP$, &
        "dlgPW", NUL_WINCLASS$, NUL_WINSTYLE, NUL_WINSTYLEX, &
        NUL_CTYPE2
        
    do
        xcall INFLD, 2,20,16,0,"|GAS]1", askpw$, inxctl, "dlgPW", 0, exitcode
            
        if askpw$ = pw$ then
            Fn'Ask'Password = .TRUE
            exit
        elseif exitcode = 0 and askpw$ # "" then
            xcall MSGBOX,"Sorry, wrong password. Try again or hit ESC to exit.", &
                prog$, MBTN_OK, MBICON_STOP, MBMISC_TASKMODAL
        else
            exit
        endif
    loop
    
    xcall AUI, AUI_CONTROL, CTLOP_DEL, "dlgPW"      ! close the dialog
    
EndFunction

++endif
