CURLOPT_USERNAME(3)

πŸ’… CURLOPT_USERNAME πŸ’…

okay so real talk, this is the <curl/curl.h> girlie whose whole job is telling curl who you are when a server asks. it lives in the Library Functions Manual, and honestly? iconic behavior. ✨


🌸 NAME 🌸

CURLOPT_USERNAME β€” the username to use in authentication 🫢


✨ SYNOPSIS ✨

#include <curl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_USERNAME,
                          char *username);

πŸŽ€ DESCRIPTION πŸŽ€

so you pass a char pointer as the parameter, and that pointer should point to a null-terminated username β€” like, the actual username you wanna use for the transfer. simple as that, no cap. πŸ’–

CURLOPT_USERNAME(3) sets the username that gets used in protocol authentication. and bestie, listen: you should not use this option together with the older CURLOPT_USERPWD(3) option. pick one, ok? don't be messy. πŸ™ˆ

now for the ✨situations✨:

  • if you're doing Kerberos V5 authentication against a Windows based server, you should include the domain name so the server can successfully obtain a Kerberos Ticket. skip it and the initial part of the authentication handshake may fail. πŸ’€ like literally, it'll just not work.
  • if you're using NTLM, you can just specify the username plain, no domain name, should the server be part of a single domain and forest. easy. 🌸
  • wanna include the domain name? use either Down-Level Logon Name or UPN (User Principal Name) formats. for example, EXAMPLEser and user@example.com respectively. πŸ¦‹
  • some HTTP servers (on Windows) support inclusion of the domain for Basic authentication as well. cute of them honestly. ✨

and if you also need the password and login options along with the username? that's what CURLOPT_PASSWORD(3) and CURLOPT_LOGIN_OPTIONS(3) are for. the whole friend group fr fr. πŸ‘‘

good news for your memory management anxiety: the application does not have to keep the string around after setting this option. curl handles it. you're free. πŸ•ŠοΈ


πŸ¦‹ DEFAULT πŸ¦‹

blank πŸ«₯


πŸ‘‘ PROTOCOLS πŸ‘‘

this functionality affects all supported protocols. all of them. every single one. main character energy tbh. 🌈


πŸ’œ EXAMPLE πŸ’œ

int main(void)
{
  CURL *curl = curl_easy_init();
  if(curl) {
    CURLcode result;
    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");

    curl_easy_setopt(curl, CURLOPT_USERNAME, "clark");

    result = curl_easy_perform(curl);

    curl_easy_cleanup(curl);
  }
}

look at clark go. we love a named user πŸ₯ΉπŸ’«


🌟 AVAILABILITY 🌟

added in curl 7.19.1 β€” a whole era ✨


πŸ”₯ RETURN VALUE πŸ”₯

curl_easy_setopt(3) returns a CURLcode indicating success or error. bestie breakdown:

  • CURLE_OK (0) means everything was OK πŸ’š
  • non-zero means an error occurred 😭 β€” go check libcurl-errors(3)

πŸ“ SEE ALSO πŸ“

go read them, they're all part of the same squad 🫢


and that's the page, bestie!! brought to you by libcurl, dated 2026-10-12 β€” mwah, go authenticate something cute πŸ’…βœ¨

πŸ“¦ where this page comes from