Jump to content
Sign in to follow this  

Repeated Login Best Practice

Recommended Posts

Posted (edited)

HI all,

It may be because it's still early in the day for me, however I'm having issues trying to figure out best practice for something. My issue is as follows:

I'm automating using an API that requires authentication. Since I need to authorize for every WinHTTP.Open() I've been considering storing the password by setting it using a function like so:

_SetLogin($vData, $sPassword="")
    Local Static $sUser
    Local Static $sPass

    If IsObj($vData) Then ; If oHTTP object
        $vData.SetCredentials($sUser, $sPass, 0)
        $sUser = $vData
        $sPass = $sPassword

Func _DoThing($sAPI, $iParam1, $iParam2)

    Local $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")

    $oHTTP.Open("POST", $sAPI & "User/" & $iParam1 & "/Dialogs", False)
    If @error Then Return SetError(1, @extended, @error)


    If @error Then Return SetError(2, 0, 0)

    If $oHTTP.Status <> STATUS_SUCCESS Then Return SetError($oHTTP.Status, 0, $oHTTP.ResponseText)

    Return SetError(0, 0, $oHTTP.ResponseText)


_DoThing("http://API/API", 125, 125)

Any advice on if there's better way to do this or any advice on best practice would be appreciated. Thanks in advance!


Edited by rcmaehl

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects
Cisco FinesseGithubIRC UDFWindowEx UDF


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this