xref: /aosp_15_r20/external/curl/docs/libcurl/opts/CURLOPT_USERPWD.md (revision 6236dae45794135f37c4eb022389c904c8b0090d)
1*6236dae4SAndroid Build Coastguard Worker---
2*6236dae4SAndroid Build Coastguard Workerc: Copyright (C) Daniel Stenberg, <[email protected]>, et al.
3*6236dae4SAndroid Build Coastguard WorkerSPDX-License-Identifier: curl
4*6236dae4SAndroid Build Coastguard WorkerTitle: CURLOPT_USERPWD
5*6236dae4SAndroid Build Coastguard WorkerSection: 3
6*6236dae4SAndroid Build Coastguard WorkerSource: libcurl
7*6236dae4SAndroid Build Coastguard WorkerSee-also:
8*6236dae4SAndroid Build Coastguard Worker  - CURLOPT_PASSWORD (3)
9*6236dae4SAndroid Build Coastguard Worker  - CURLOPT_PROXYUSERPWD (3)
10*6236dae4SAndroid Build Coastguard Worker  - CURLOPT_USERNAME (3)
11*6236dae4SAndroid Build Coastguard WorkerProtocol:
12*6236dae4SAndroid Build Coastguard Worker  - All
13*6236dae4SAndroid Build Coastguard WorkerAdded-in: 7.1
14*6236dae4SAndroid Build Coastguard Worker---
15*6236dae4SAndroid Build Coastguard Worker
16*6236dae4SAndroid Build Coastguard Worker# NAME
17*6236dae4SAndroid Build Coastguard Worker
18*6236dae4SAndroid Build Coastguard WorkerCURLOPT_USERPWD - username and password to use in authentication
19*6236dae4SAndroid Build Coastguard Worker
20*6236dae4SAndroid Build Coastguard Worker# SYNOPSIS
21*6236dae4SAndroid Build Coastguard Worker
22*6236dae4SAndroid Build Coastguard Worker~~~c
23*6236dae4SAndroid Build Coastguard Worker#include <curl/curl.h>
24*6236dae4SAndroid Build Coastguard Worker
25*6236dae4SAndroid Build Coastguard WorkerCURLcode curl_easy_setopt(CURL *handle, CURLOPT_USERPWD, char *userpwd);
26*6236dae4SAndroid Build Coastguard Worker~~~
27*6236dae4SAndroid Build Coastguard Worker
28*6236dae4SAndroid Build Coastguard Worker# DESCRIPTION
29*6236dae4SAndroid Build Coastguard Worker
30*6236dae4SAndroid Build Coastguard WorkerPass a char pointer as parameter, pointing to a null-terminated login details
31*6236dae4SAndroid Build Coastguard Workerstring for the connection. The format of which is: [username]:[password].
32*6236dae4SAndroid Build Coastguard Worker
33*6236dae4SAndroid Build Coastguard WorkerWhen using Kerberos V5 authentication with a Windows based server, you should
34*6236dae4SAndroid Build Coastguard Workerspecify the username part with the domain name in order for the server to
35*6236dae4SAndroid Build Coastguard Workersuccessfully obtain a Kerberos Ticket. If you do not then the initial part of
36*6236dae4SAndroid Build Coastguard Workerthe authentication handshake may fail.
37*6236dae4SAndroid Build Coastguard Worker
38*6236dae4SAndroid Build Coastguard WorkerWhen using NTLM, the username can be specified simply as the username without
39*6236dae4SAndroid Build Coastguard Workerthe domain name should the server be part of a single domain and forest.
40*6236dae4SAndroid Build Coastguard Worker
41*6236dae4SAndroid Build Coastguard WorkerTo specify the domain name use either Down-Level Logon Name or UPN (User
42*6236dae4SAndroid Build Coastguard WorkerPrincipal Name) formats. For example **EXAMPLE\user** and **[email protected]**
43*6236dae4SAndroid Build Coastguard Workerrespectively.
44*6236dae4SAndroid Build Coastguard Worker
45*6236dae4SAndroid Build Coastguard WorkerSome HTTP servers (on Windows) support inclusion of the domain for Basic
46*6236dae4SAndroid Build Coastguard Workerauthentication as well.
47*6236dae4SAndroid Build Coastguard Worker
48*6236dae4SAndroid Build Coastguard WorkerWhen using HTTP and CURLOPT_FOLLOWLOCATION(3), libcurl might perform several
49*6236dae4SAndroid Build Coastguard Workerrequests to possibly different hosts. libcurl only sends this user and
50*6236dae4SAndroid Build Coastguard Workerpassword information to hosts using the initial hostname (unless
51*6236dae4SAndroid Build Coastguard WorkerCURLOPT_UNRESTRICTED_AUTH(3) is set), so if libcurl follows redirects to other
52*6236dae4SAndroid Build Coastguard Workerhosts, it does not send the user and password to those. This is enforced to
53*6236dae4SAndroid Build Coastguard Workerprevent accidental information leakage.
54*6236dae4SAndroid Build Coastguard Worker
55*6236dae4SAndroid Build Coastguard WorkerUse CURLOPT_HTTPAUTH(3) to specify the authentication method for HTTP
56*6236dae4SAndroid Build Coastguard Workerbased connections or CURLOPT_LOGIN_OPTIONS(3) to control IMAP, POP3 and
57*6236dae4SAndroid Build Coastguard WorkerSMTP options.
58*6236dae4SAndroid Build Coastguard Worker
59*6236dae4SAndroid Build Coastguard WorkerThe user and password strings are not URL decoded, so there is no way to send
60*6236dae4SAndroid Build Coastguard Workerin a username containing a colon using this option. Use CURLOPT_USERNAME(3)
61*6236dae4SAndroid Build Coastguard Workerfor that, or include it in the URL.
62*6236dae4SAndroid Build Coastguard Worker
63*6236dae4SAndroid Build Coastguard WorkerThe application does not have to keep the string around after setting this
64*6236dae4SAndroid Build Coastguard Workeroption.
65*6236dae4SAndroid Build Coastguard Worker
66*6236dae4SAndroid Build Coastguard WorkerUsing this option multiple times makes the last set string override the
67*6236dae4SAndroid Build Coastguard Workerprevious ones. Set it to NULL to disable its use again.
68*6236dae4SAndroid Build Coastguard Worker
69*6236dae4SAndroid Build Coastguard Worker# DEFAULT
70*6236dae4SAndroid Build Coastguard Worker
71*6236dae4SAndroid Build Coastguard WorkerNULL
72*6236dae4SAndroid Build Coastguard Worker
73*6236dae4SAndroid Build Coastguard Worker# %PROTOCOLS%
74*6236dae4SAndroid Build Coastguard Worker
75*6236dae4SAndroid Build Coastguard Worker# EXAMPLE
76*6236dae4SAndroid Build Coastguard Worker
77*6236dae4SAndroid Build Coastguard Worker~~~c
78*6236dae4SAndroid Build Coastguard Workerint main(void)
79*6236dae4SAndroid Build Coastguard Worker{
80*6236dae4SAndroid Build Coastguard Worker  CURL *curl = curl_easy_init();
81*6236dae4SAndroid Build Coastguard Worker  if(curl) {
82*6236dae4SAndroid Build Coastguard Worker    CURLcode res;
83*6236dae4SAndroid Build Coastguard Worker    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
84*6236dae4SAndroid Build Coastguard Worker
85*6236dae4SAndroid Build Coastguard Worker    curl_easy_setopt(curl, CURLOPT_USERPWD, "clark:kent");
86*6236dae4SAndroid Build Coastguard Worker
87*6236dae4SAndroid Build Coastguard Worker    res = curl_easy_perform(curl);
88*6236dae4SAndroid Build Coastguard Worker
89*6236dae4SAndroid Build Coastguard Worker    curl_easy_cleanup(curl);
90*6236dae4SAndroid Build Coastguard Worker  }
91*6236dae4SAndroid Build Coastguard Worker}
92*6236dae4SAndroid Build Coastguard Worker~~~
93*6236dae4SAndroid Build Coastguard Worker
94*6236dae4SAndroid Build Coastguard Worker# %AVAILABILITY%
95*6236dae4SAndroid Build Coastguard Worker
96*6236dae4SAndroid Build Coastguard Worker# RETURN VALUE
97*6236dae4SAndroid Build Coastguard Worker
98*6236dae4SAndroid Build Coastguard WorkerReturns CURLE_OK on success or
99*6236dae4SAndroid Build Coastguard WorkerCURLE_OUT_OF_MEMORY if there was insufficient heap space.
100