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