WebSetUserAuth Function


Sets the password for user authentication. This setting is ignored if a user name and/or password is specified in the URL of a low-level call.

Note: This function overrides the corresponding setting on the Authentication tab of the Profile SettingsWeb dialog. It also sets the credentials for Basic, Digest and NTLM/Kerberos authentication, if they are not set explicitly.

Include file



WebSetUserAuth( in sUsername     : string allownull,
                in sPassword     : string optional,
                in sUrl          : string optional,
                in sRealm        : string optional,
                in bReactiveOnly : boolean optional): boolean;

Return value

  • true if successful

  • false otherwise

Parameter Description
sUsername User name. This parameter may be NULL.
sPassword Password. This parameter may be NULL (optional).
sUrl URL representing protection space for basic authentication (optional)
sRealm Realm for which to set authentication (optional). This realm then provides a special context for the username/password to a Web site. For example, www.MyCompany.com uses realm "www.MyCompany.com", whereas www.MyCompany.com/support uses realm "MyCompany support".
bReactiveOnly If this parameter is set to true (default is false), the user and password pair can only be used in a reaction to a 401 response from the server.

Calling this function inserts the username/password pair into the authentication database used when a server requests basic authentication (code 401). On subsequent requests, the authentication header line will be added to the request headers automatically.

  • To set the default username password, call WebSetUserAuth("user1", "pass1");

  • To delete the default username/password, call WebSetUserAuth("", ""); This does not remove the entry from the authentication database.

  • To remove all cached authentication entries from the cookie database, call WebSetUserAuth(NULL, NULL);

  • In addition, you can add authentication entries directly to the authentication database by providing a protection space and the realm. For example, WebSetUserAuth("BasicAuthUser", "BasicAuthPass", "http://lab1/testsite/", "lab1");


  transaction TMyTransaction
    // Enable user authentication
    // User sends e-mail address as password
    WebSetUserAuth("steve", "steve@mydomain.com");

     // Now send the request including username and password
    WebUrl("http://www.mydomain.com/", 0.0);

     // Disable user authentication
    WebSetUserAuth(NULL, NULL);
  end TMyTransaction;

Sample scripts


SilkEssential sample