[#boost-urls-url-set_userinfo-0b]
= xref:boost.adoc[boost]::xref:boost/urls.adoc[urls]::xref:boost/urls/url.adoc[url]::set&lowbar;userinfo
:relfileprefix: ../../../
:mrdocs:


Set the userinfo

== Synopsis


Declared in `&lt;https://www.github.com/boostorg/url/blob/develop/include/boost/url/url.hpp#L422[boost&sol;url&sol;url&period;hpp]&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:boost/urls/url.adoc[url]&
set&lowbar;userinfo(core::string&lowbar;view s);
----

== Description


The userinfo is set to the given string,        which may contain percent&hyphen;escapes&period;        Any special or reserved characters in the        string are automatically percent&hyphen;encoded&period;        The effects on the user and password        depend on the presence of a colon (&apos;&colon;&apos;)        in the string&colon;

* If an unescaped colon exists, the        characters up to the colon become
        the user and the rest of the characters        after the colon become the password&period;
        In this case 
has&lowbar;password
 returns        true&period; Otherwise,
* If there is no colon, the user is        set to the string&period; The function
        
has&lowbar;password
 returns false&period;

[NOTE]
The interpretation of the userinfo as        individual user and password components        is scheme&hyphen;dependent&period; Transmitting        passwords in URLs is deprecated&period;


=== Example

[,cpp]
----
assert( url( "http://example.com" ).set_userinfo( "user:pass" ).encoded_user() == "user" );
----

=== Complexity

Linear in `this&hyphen;&gt;size() &plus; s&period;size()`&period;


=== Exception Safety

Strong guarantee&period;        Calls to allocate may throw&period;


=== BNF

[,cpp]
----
userinfo      = [ [ user ] [ ':' password ] ]

user          = *( unreserved / pct-encoded / sub-delims )
password      = *( unreserved / pct-encoded / sub-delims / ":" )
----

=== Specification

* link:https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1[            3&period;2&period;1&period; User Information (rfc3986)]



== Parameters


|===
| Name | Description

| *s*
| The string to set&period;


|===

== See Also


xref:boost/urls/url_base/remove_userinfo.adoc[remove&lowbar;userinfo],            xref:boost/urls/url_base/set_encoded_userinfo.adoc[set&lowbar;encoded&lowbar;userinfo]&period;






[.small]#Created with https://www.mrdocs.com[MrDocs]#
