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

Set the userinfo

== Synopsis

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

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:boost/urls/url_base.adoc[url&lowbar;base]&
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 xref:boost/urls/url_view_base/has_password.adoc[`has&lowbar;password`] returns true&period; Otherwise,
* If there is no colon, the user is set to the string&period; The function xref:boost/urls/url_view_base/has_password.adoc[`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

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

== Return Value

`&ast;this`

== Parameters

[cols="1,4"]
|===
|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]#
