Function Reference


Creates and displays a configurable dialog box that accepts credentials information from a user

#include <WinAPIDlg.au3>
_WinAPI_ShellUserAuthenticationDlg ( $sCaption, $sMessage, $sUser, $sPassword, $sTarget [, $iFlags = 0 [, $iError = 0 [, $bSave = False [, $hBitmap = 0 [, $hParent = 0]]]]] )


$sCaption The title for the dialog box.
$sMessage A brief message to display in the dialog box.
$sUser The user name to populate the credential fields in the dialog box. For domain users, the string must
be in the following format (if domain is not specified, the trget string is used as the domain):

$sPassword The initial password.
$sTarget The name of the target, typically a server name. This parameter is used to identify target information
when storing and retrieving credentials.
$iFlags [optional] The flags that specifies behavior for this function. It can be a bitwise-OR combination of zero
or more of the following values.
$iError [optional] The system error code that specifies why the credential dialog box is needed.
$bSave [optional] Specifies whether the "Save" check box is selected in the dialog box (it makes sense only if the
$CREDUI_FLAGS_SHOW_SAVE_CHECK_BOX flag is used), valid values:
    True - Selected.
    False - Deselected (Default).
$hBitmap [optional] A bitmap handle to display in the dialog box. If this parameter is 0, the default bitmap is used.
The bitmap size is limited to 320x60 pixels.
$hParent [optional] The dialog box is modal with respect to the parent window. If this parameter is 0, the desktop
is the parent window of the dialog box.

Return Value

Success: The array containing the following information:
[0] - The user name, including domain name (if necessary).
[1] - The password.
[2] - The state of the "Save" check box.
Failure: Sets the @error flag to non-zero. If the function is cancelled by the user, @extended flag will
contain the ERROR_CANCELLED (1223) system error code. Any other value indicates that the function
failed to load.


Credentials are stored in the credential manager based on target name. Each target name is stored as generally as
possible without colliding with credentials already stored in the credential manager. Because credentials are stored
by target name, a particular user can only have one credential per target stored in the credential manager.



See Also

Search CredUIPromptForCredentials in MSDN Library.


#include <APIDlgConstants.au3>
#include <Crypt.au3>
#include <MsgBoxConstants.au3>
#include <WinAPI.au3>
#include <WinAPIDlg.au3>

Local $hBitmap = _WinAPI_LoadImage(0, @ScriptDir & '\Extras\Authentication.bmp', $IMAGE_BITMAP, 0, 0, $LR_LOADFROMFILE)
Local $aData[3] = ['', '', 0]

While 1
    $aData = _WinAPI_ShellUserAuthenticationDlg('Authentication', 'To continue, type a login and password, and then click OK.', $aData[0], $aData[1], 'MyScript', BitOR($CREDUI_FLAGS_ALWAYS_SHOW_UI, $CREDUI_FLAGS_EXPECT_CONFIRMATION, $CREDUI_FLAGS_GENERIC_CREDENTIALS, $CREDUI_FLAGS_SHOW_SAVE_CHECK_BOX), 0, $aData[2], $hBitmap)
    If @error Then Exit

    If (StringCompare($aData[0], 'AutoIt')) Or (StringCompare($aData[1], StringEncrypt(False, 'DC7E430A1C88', '123'))) Then
        If $aData[2] Then
            _WinAPI_ConfirmCredentials('MyScript', 0)
        MsgBox(BitOR($MB_ICONERROR, $MB_SYSTEMMODAL), 'Error', 'You have typed an incorrect login or password, it should be "AutoIt" and "123".')
        If $aData[2] Then
            _WinAPI_ConfirmCredentials('MyScript', 1)

Func StringEncrypt($bEncrypt, $sData, $sPassword)
    _Crypt_Startup() ; Start the Crypt library.
    Local $sReturn = ''
    If $bEncrypt Then ; If the flag is set to True then encrypt, otherwise decrypt.
        $sReturn = _Crypt_EncryptData($sData, $sPassword, $CALG_RC4)
        $sReturn = BinaryToString(_Crypt_DecryptData($sData, $sPassword, $CALG_RC4))
    _Crypt_Shutdown() ; Shutdown the Crypt library.
    Return $sReturn
EndFunc   ;==>StringEncrypt