xref: /curl/docs/libcurl/opts/CURLOPT_USERNAME.md (revision 5a488251)
1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLOPT_USERNAME
5Section: 3
6Source: libcurl
7See-also:
8  - CURLOPT_HTTPAUTH (3)
9  - CURLOPT_PASSWORD (3)
10  - CURLOPT_PROXYAUTH (3)
11  - CURLOPT_USERPWD (3)
12Protocol:
13  - All
14Added-in: 7.19.1
15---
16
17# NAME
18
19CURLOPT_USERNAME - username to use in authentication
20
21# SYNOPSIS
22
23~~~c
24#include <curl/curl.h>
25
26CURLcode curl_easy_setopt(CURL *handle, CURLOPT_USERNAME,
27                          char *username);
28~~~
29
30# DESCRIPTION
31
32Pass a char pointer as parameter, which should be pointing to the
33null-terminated username to use for the transfer.
34
35CURLOPT_USERNAME(3) sets the username to be used in protocol
36authentication. You should not use this option together with the (older)
37CURLOPT_USERPWD(3) option.
38
39When using Kerberos V5 authentication with a Windows based server, you should
40include the domain name in order for the server to successfully obtain a
41Kerberos Ticket. If you do not then the initial part of the authentication
42handshake may fail.
43
44When using NTLM, the username can be specified simply as the username without
45the domain name should the server be part of a single domain and forest.
46
47To include the domain name use either Down-Level Logon Name or UPN (User
48Principal Name) formats. For example, **EXAMPLE\user** and
49**user@example.com** respectively.
50
51Some HTTP servers (on Windows) support inclusion of the domain for Basic
52authentication as well.
53
54To specify the password and login options, along with the username, use the
55CURLOPT_PASSWORD(3) and CURLOPT_LOGIN_OPTIONS(3) options.
56
57The application does not have to keep the string around after setting this
58option.
59
60# DEFAULT
61
62blank
63
64# %PROTOCOLS%
65
66# EXAMPLE
67
68~~~c
69int main(void)
70{
71  CURL *curl = curl_easy_init();
72  if(curl) {
73    CURLcode res;
74    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
75
76    curl_easy_setopt(curl, CURLOPT_USERNAME, "clark");
77
78    res = curl_easy_perform(curl);
79
80    curl_easy_cleanup(curl);
81  }
82}
83~~~
84
85# %AVAILABILITY%
86
87# RETURN VALUE
88
89Returns CURLE_OK if the option is supported, CURLE_UNKNOWN_OPTION if not, or
90CURLE_OUT_OF_MEMORY if there was insufficient heap space.
91