RequestMessagePassword.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System.Text;
  2. namespace Renci.SshNet.Messages.Authentication
  3. {
  4. /// <summary>
  5. /// Represents "password" SSH_MSG_USERAUTH_REQUEST message.
  6. /// </summary>
  7. internal class RequestMessagePassword : RequestMessage
  8. {
  9. /// <summary>
  10. /// Gets the name of the authentication method.
  11. /// </summary>
  12. /// <value>
  13. /// The name of the method.
  14. /// </value>
  15. public override string MethodName
  16. {
  17. get
  18. {
  19. return "password";
  20. }
  21. }
  22. /// <summary>
  23. /// Gets authentication password.
  24. /// </summary>
  25. public string Password { get; private set; }
  26. /// <summary>
  27. /// Gets new authentication password.
  28. /// </summary>
  29. public string NewPassword { get; private set; }
  30. /// <summary>
  31. /// Initializes a new instance of the <see cref="RequestMessagePassword"/> class.
  32. /// </summary>
  33. /// <param name="serviceName">Name of the service.</param>
  34. /// <param name="username">Authentication username.</param>
  35. /// <param name="password">Authentication password.</param>
  36. public RequestMessagePassword(ServiceName serviceName, string username, string password)
  37. : base(serviceName, username)
  38. {
  39. this.Password = password ?? string.Empty;
  40. }
  41. /// <summary>
  42. /// Initializes a new instance of the <see cref="RequestMessagePassword"/> class.
  43. /// </summary>
  44. /// <param name="serviceName">Name of the service.</param>
  45. /// <param name="username">Authentication username.</param>
  46. /// <param name="password">Authentication password.</param>
  47. /// <param name="newPassword">New authentication password.</param>
  48. public RequestMessagePassword(ServiceName serviceName, string username, string password, string newPassword)
  49. : this(serviceName, username, password)
  50. {
  51. this.NewPassword = newPassword ?? string.Empty;
  52. }
  53. /// <summary>
  54. /// Called when type specific data need to be saved.
  55. /// </summary>
  56. protected override void SaveData()
  57. {
  58. base.SaveData();
  59. this.Write(!string.IsNullOrEmpty(this.NewPassword));
  60. this.Write(this.Password);
  61. if (!string.IsNullOrEmpty(this.NewPassword))
  62. {
  63. this.Write(this.NewPassword);
  64. }
  65. }
  66. }
  67. }