using System.Text;
namespace Renci.SshNet.Messages.Authentication
{
    /// 
    /// Represents "password" SSH_MSG_USERAUTH_REQUEST message.
    /// 
    internal class RequestMessagePassword : RequestMessage
    {
        /// 
        /// Gets the name of the authentication method.
        /// 
        /// 
        /// The name of the method.
        /// 
        public override string MethodName
        {
            get
            {
                return "password";
            }
        }
        /// 
        /// Gets authentication password.
        /// 
        public string Password { get; private set; }
        /// 
        /// Gets new authentication password.
        /// 
        public string NewPassword { get; private set; }
        /// 
        /// Initializes a new instance of the  class.
        /// 
        /// Name of the service.
        /// Authentication username.
        /// Authentication password.
        public RequestMessagePassword(ServiceName serviceName, string username, string password)
            : base(serviceName, username)
        {
            this.Password = password ?? string.Empty;
        }
        /// 
        /// Initializes a new instance of the  class.
        /// 
        /// Name of the service.
        /// Authentication username.
        /// Authentication password.
        /// New authentication password.
        public RequestMessagePassword(ServiceName serviceName, string username, string password, string newPassword)
            : this(serviceName, username, password)
        {
            this.NewPassword = newPassword ?? string.Empty;
        }
        /// 
        /// Called when type specific data need to be saved.
        /// 
        protected override void SaveData()
        {
            base.SaveData();
            this.Write(!string.IsNullOrEmpty(this.NewPassword));
            this.Write(this.Password);
            if (!string.IsNullOrEmpty(this.NewPassword))
            {
                this.Write(this.NewPassword);
            }
        }
    }
}