# Function Reference

# _WinAPI_ConfirmCredentials

Confirms the validity of the credential harvested

#include <WinAPIDlg.au3>
_WinAPI_ConfirmCredentials ( $sTarget, $bConfirm )

## Parameters

$sTarget | The string that contains the name of the target for the credentials, typically a domain or server name. This must be the same value passed to _WinAPI_ShellUserAuthenticationDlg() function.
$bConfirm | Specifies whether the credentials returned from the prompt function are valid, valid values: True - The credentials are stored in the credential manager. False - The credentials are not stored and various pieces of memory are cleaned up.

## Return Value

Success: | 1.
Failure: | 0 and sets the @error flag to non-zero, @extended flag may contain the system error code.

## Remarks

This function must be called after each successful call to _WinAPI_ShellUserAuthenticationDlg() with the $CREDUI_FLAGS_EXPECT_CONFIRMATION flag set.

## Related

_WinAPI_ShellUserAuthenticationDlg

## See Also

Search CredUIConfirmCredentials in MSDN Library.

## Example

    #include "Extras\HelpFileInternals.au3"

    #include <Crypt.au3>
    #include <MsgBoxConstants.au3>
    #include <WinAPIDlg.au3>
    #include <WinAPIRes.au3>

    Local $sBmp = _Extras_PathFull('Authentication.bmp')
    Local $hBitmap = _WinAPI_LoadImage(0, $sBmp, $IMAGE_BITMAP, 0, 0, $LR_LOADFROMFILE)
    Local $aData[3] = ['', '', 0]

    Local $sUser = 'AutoIt'
    Local $sPassword = '123'

    Local $sPasswordToCryptPassword = '1234'
    Local $dPaswordEncrypted = StringEncrypt($sPassword, $sPasswordToCryptPassword)

    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], StringDecrypt($dPaswordEncrypted, $sPasswordToCryptPassword)) Then
            If $aData[2] Then
                _WinAPI_ConfirmCredentials('MyScript', False)
            EndIf
            MsgBox(($MB_ICONERROR + $MB_SYSTEMMODAL), 'Error', 'You have typed an incorrect login or password, it should be "' & $sUser & '" and "' & $sPassword & '".')
        Else
            If $aData[2] Then
                _WinAPI_ConfirmCredentials('MyScript', True)
            EndIf
            ExitLoop
        EndIf
    WEnd

    Func StringEncrypt($sData, $sPassword)
        _Crypt_Startup() ; Start the Crypt library.
        Local $sReturn = _Crypt_EncryptData($sData, $sPassword, $CALG_RC4)
        _Crypt_Shutdown() ; Shutdown the Crypt library.
        Return $sReturn
    EndFunc   ;==>StringEncrypt

    Func StringDecrypt($sData, $dPassword)
        _Crypt_Startup() ; Start the Crypt library.
        Local $sReturn = BinaryToString(_Crypt_DecryptData($sData, $dPassword, $CALG_RC4))
        _Crypt_Shutdown() ; Shutdown the Crypt library.
        Return $sReturn
    EndFunc   ;==>StringDecrypt