using System;
using System.Collections.Generic;
using System.Text;
namespace FastReport.Messaging.Authentication.Sasl
{
///
/// The PLAIN SASL authentication mechanism.
///
public class PlainMechanism : SaslMechanism
{
#region Constants
///
/// The mechanism name.
///
public const string MECHANISM_NAME = "PLAIN";
#endregion // Constants
#region Constructors
///
/// Initializes a new instance of the class.
///
/// The username.
/// The user's password.
public PlainMechanism(string username, string password)
{
Name = MECHANISM_NAME;
Username = username;
Password = password;
}
#endregion // Constructors
#region Protected Methods
///
/// Computes the client response for server challenge.
///
/// The challenge from server. Usually empty for PLAIN mechanism.
/// The response from client.
protected override byte[] ComputeResponse(byte[] challenge)
{
if (String.IsNullOrEmpty(Username) || String.IsNullOrEmpty(Password))
{
return null;
}
return Encoding.UTF8.GetBytes("\0" + Username + "\0" + Password);
}
#endregion // Protected Methods
}
}