Docs Menu
Docs Home
/ /

PLAIN SASL Authentication

Note

PLAIN SASL authentication is available only in the MongoDB Enterprise Edition.

The PLAIN Simple Authentication and Security Layer (SASL) mechanism, as defined in RFC 4616, is a username and password authentication mechanism often used with Transport Layer Security (TLS) or another encryption layer.

Important

PLAIN SASL is a clear-text authentication mechanism. We strongly recommend that you use TLS/SSL with certificate validation when using PLAIN SASL to authenticate to MongoDB.

To learn how to enable TLS for your connection, see TLS/SSL.

The code example on this page uses the following placeholders:

  • <db_username>: Username to authenticate.

  • <db_password>: Password for <db_username>.

  • <hostname>: Network address of your MongoDB deployment.

  • <port>: Port number of your MongoDB deployment. If you omit this parameter, MongoDB uses the default port number (27017).

To use the code example on this page, replace these placeholders with your own values.

To authenticate with PLAIN SASL, set the authMechanism connection option to PLAIN. You set this option in the connection URI.

The following example shows how to specify the PLAIN SASL mechanism and enable TLS in the connection string:

auto uri = mongocxx::uri("mongodb://<db_username>:<db_password>@<hostname>:<port>/?"
"authMechanism=PLAIN&tls=true");
auto client = mongocxx::client(uri);

To learn more about creating a mongocxx::client object in C++ driver, see the following API documentation:

Back

Kerberos (GSSAPI)

On this page