Class MongoCredential
Credential to access a MongoDB database.
[Serializable]
public class MongoCredential : IEquatable<MongoCredential>
- Inheritance
-
MongoCredential
- Implements
- Inherited Members
Constructors
MongoCredential(string, MongoIdentity, MongoIdentityEvidence)
Initializes a new instance of the MongoCredential class.
public MongoCredential(string mechanism, MongoIdentity identity, MongoIdentityEvidence evidence)
Parameters
mechanismstringMechanism to authenticate with.
identityMongoIdentityThe identity.
evidenceMongoIdentityEvidenceThe evidence.
Properties
Evidence
Gets the evidence.
public MongoIdentityEvidence Evidence { get; }
Property Value
Identity
Gets the identity.
public MongoIdentity Identity { get; }
Property Value
Mechanism
Gets the mechanism to authenticate with.
public string Mechanism { get; }
Property Value
Password
Gets the password.
[Obsolete("Use Evidence instead.")]
public string Password { get; }
Property Value
Source
Gets the source.
public string Source { get; }
Property Value
Username
Gets the username.
public string Username { get; }
Property Value
Methods
CreateCredential(string, string, SecureString)
Creates a default credential. Less secure when used in conjunction with SCRAM-SHA-256, due to the need to store the password in a managed string in order to SaslPrep it.
public static MongoCredential CreateCredential(string databaseName, string username, SecureString password)
Parameters
databaseNamestringName of the database.
usernamestringThe username.
passwordSecureStringThe password.
Returns
- MongoCredential
A default credential.
CreateCredential(string, string, string)
Creates a default credential.
public static MongoCredential CreateCredential(string databaseName, string username, string password)
Parameters
databaseNamestringName of the database.
usernamestringThe username.
passwordstringThe password.
Returns
- MongoCredential
A default credential.
CreateGssapiCredential(string)
Creates a GSSAPI credential.
public static MongoCredential CreateGssapiCredential(string username)
Parameters
usernamestringThe username.
Returns
- MongoCredential
A credential for GSSAPI.
Remarks
This overload is used primarily on linux.
CreateGssapiCredential(string, SecureString)
Creates a GSSAPI credential.
public static MongoCredential CreateGssapiCredential(string username, SecureString password)
Parameters
usernamestringThe username.
passwordSecureStringThe password.
Returns
- MongoCredential
A credential for GSSAPI.
CreateGssapiCredential(string, string)
Creates a GSSAPI credential.
public static MongoCredential CreateGssapiCredential(string username, string password)
Parameters
Returns
- MongoCredential
A credential for GSSAPI.
CreateMongoCRCredential(string, string, SecureString)
Creates a credential used with MONGODB-CR.
[Obsolete("MONGODB-CR was replaced by SCRAM-SHA-1 in MongoDB 3.0, and is now deprecated.")]
public static MongoCredential CreateMongoCRCredential(string databaseName, string username, SecureString password)
Parameters
databaseNamestringName of the database.
usernamestringThe username.
passwordSecureStringThe password.
Returns
- MongoCredential
A credential for MONGODB-CR.
CreateMongoCRCredential(string, string, string)
Creates a credential used with MONGODB-CR.
[Obsolete("MONGODB-CR was replaced by SCRAM-SHA-1 in MongoDB 3.0, and is now deprecated.")]
public static MongoCredential CreateMongoCRCredential(string databaseName, string username, string password)
Parameters
databaseNamestringName of the database.
usernamestringThe username.
passwordstringThe password.
Returns
- MongoCredential
A credential for MONGODB-CR.
CreateMongoX509Credential(string)
Creates a credential used with MONGODB-X509.
public static MongoCredential CreateMongoX509Credential(string username = null)
Parameters
usernamestringThe username.
Returns
- MongoCredential
A credential for MONGODB-X509.
CreatePlainCredential(string, string, SecureString)
Creates a PLAIN credential.
public static MongoCredential CreatePlainCredential(string databaseName, string username, SecureString password)
Parameters
databaseNamestringName of the database.
usernamestringThe username.
passwordSecureStringThe password.
Returns
- MongoCredential
A credential for PLAIN.
CreatePlainCredential(string, string, string)
Creates a PLAIN credential.
public static MongoCredential CreatePlainCredential(string databaseName, string username, string password)
Parameters
databaseNamestringName of the database.
usernamestringThe username.
passwordstringThe password.
Returns
- MongoCredential
A credential for PLAIN.
Equals(MongoCredential)
Compares this MongoCredential to another MongoCredential.
public bool Equals(MongoCredential rhs)
Parameters
rhsMongoCredentialThe other credential.
Returns
- bool
True if the two credentials are equal.
Equals(object)
Compares this MongoCredential to another MongoCredential.
public override bool Equals(object obj)
Parameters
objobjectThe other credential.
Returns
- bool
True if the two credentials are equal.
GetHashCode()
Gets the hashcode for the credential.
public override int GetHashCode()
Returns
- int
The hashcode.
GetMechanismProperty<T>(string, T)
Gets the mechanism property.
public T GetMechanismProperty<T>(string key, T defaultValue)
Parameters
keystringThe key.
defaultValueTThe default value.
Returns
- T
The mechanism property if one was set; otherwise the default value.
Type Parameters
TThe type of the mechanism property.
ToString()
Returns a string representation of the credential.
public override string ToString()
Returns
- string
A string representation of the credential.
WithMechanismProperty(string, object)
Creates a new MongoCredential with the specified mechanism property.
public MongoCredential WithMechanismProperty(string key, object value)
Parameters
Returns
- MongoCredential
A new MongoCredential with the specified mechanism property.
Operators
operator ==(MongoCredential, MongoCredential)
Compares two MongoCredentials.
public static bool operator ==(MongoCredential lhs, MongoCredential rhs)
Parameters
lhsMongoCredentialThe first MongoCredential.
rhsMongoCredentialThe other MongoCredential.
Returns
- bool
True if the two MongoCredentials are equal (or both null).
operator !=(MongoCredential, MongoCredential)
Compares two MongoCredentials.
public static bool operator !=(MongoCredential lhs, MongoCredential rhs)
Parameters
lhsMongoCredentialThe first MongoCredential.
rhsMongoCredentialThe other MongoCredential.
Returns
- bool
True if the two MongoCredentials are not equal (or one is null and the other is not).