RequestMessagePassword.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 byte[] Password { get; private set; }
  26. /// <summary>
  27. /// Gets new authentication password.
  28. /// </summary>
  29. public byte[] 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, byte[] password)
  37. : base(serviceName, username)
  38. {
  39. this.Password = password;
  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, byte[] password, byte[] newPassword)
  49. : this(serviceName, username, password)
  50. {
  51. this.NewPassword = newPassword;
  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(this.NewPassword != null);
  60. this.Write((uint)this.Password.Length);
  61. this.Write(this.Password);
  62. if (this.NewPassword != null)
  63. {
  64. this.Write((uint)this.NewPassword.Length);
  65. this.Write(this.NewPassword);
  66. }
  67. }
  68. }
  69. }