WebSetUserAuthBasic Function

Action

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

注: This function overrides the corresponding setting on the Authentication tab of the Profile SettingsWeb dialog. In contrast to the WebSetUserAuth function, this function does not change the credentials for Digest or NTLM/Kerberos authentication.

Include file

WebAPI.bdh

Syntax

WebSetUserAuthBasic( 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 (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 (optional; 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 WebSetUserAuthBasic("user1", "pass1");

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

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

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

Example

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

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

    // Disable user authentication
    WebSetUserAuthBasic(NULL);
  end TMyTransaction;