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

Set the userinfo&period;

== Synopsis

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

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

== Description

The userinfo is set to the given string, which may contain percent&hyphen;escapes&period; Escapes in the string are preserved, and reserved characters in the string are percent&hyphen;escaped in the result&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_encoded_userinfo( "john%20doe" ).user() == "john doe" );
----
== Complexity
Linear in `this&hyphen;&gt;size() &plus; s&period;size()`&period;

== Exception Safety
Strong guarantee&period; Calls to allocate may throw&period; Exceptions thrown on invalid input&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[]

== Return Value

`&ast;this`

== Parameters

[cols=2]
|===
| Name
| Description
| *s*
| The string to set&period;
|===

== See Also

xref:boost/urls/url/remove_userinfo.adoc[`remove&lowbar;userinfo`], xref:boost/urls/url/set_userinfo.adoc[`set&lowbar;userinfo`]&period;


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