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