Password.aml 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <topic id="b7b599b2-8bc2-4276-b9a2-d73eee2426ab" revisionNumber="1">
  3. <developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
  4. <introduction>
  5. <para>
  6. This section will describe how to establish connection using username and password combination.
  7. You can provide username/password combination either directly in the client constractor using <codeEntityReference>T:Renci.SshNet.PasswordConnectionInfo</codeEntityReference> class.
  8. You use <codeEntityReference>T:Renci.SshNet.PasswordConnectionInfo</codeEntityReference> object when you need to provide additional such as timeout or simple to handle different events that can occur when establishing connection.
  9. </para>
  10. <list class="bullet">
  11. <listItem>
  12. <para>
  13. <link xlink:href="#UseUsernamePasswordSection">Use username and password to connect.</link>
  14. </para>
  15. </listItem>
  16. <listItem>
  17. <para>
  18. <link xlink:href="#UsePasswordConnectionInfoSection">Use PasswordConnectionInfo to connect.</link>
  19. </para>
  20. </listItem>
  21. <listItem>
  22. <para>
  23. <link xlink:href="#HandleExpiredPasswordSection">Handle expired password.</link>
  24. </para>
  25. </listItem>
  26. </list>
  27. </introduction>
  28. <section address="UseUsernamePasswordSection">
  29. <title>Use username and password to connect</title>
  30. <content>
  31. <para>
  32. In many scenarious all you need to know is host, username and password to establish connection, in this case you can provide this information directly to the client object.
  33. </para>
  34. <code language="cs" title="Use username and password to connect example">
  35. <![CDATA[
  36. using (var client = new SshClient("host", "username", "password"))
  37. {
  38. client.Connect();
  39. ....
  40. client.Disconnect();
  41. }
  42. ]]>
  43. </code>
  44. </content>
  45. </section>
  46. <section address="UsePasswordConnectionInfoSection">
  47. <title>Use PasswordConnectionInfo to connect</title>
  48. <content>
  49. <para>
  50. To get more control over connection proccess when using username and password combination you need to use <codeEntityReference>T:Renci.SshNet.PasswordConnectionInfo</codeEntityReference> object.
  51. </para>
  52. <code language="cs" title="How to use PasswordConnectionInfo example">
  53. <![CDATA[
  54. var connectionInfo = new PasswordConnectionInfo("host", "username", "password");
  55. using (var client = new SftpClient(connectionInfo))
  56. {
  57. client.Connect();
  58. ...
  59. client.Disconnect();
  60. }
  61. ]]>
  62. </code>
  63. </content>
  64. </section>
  65. <section address="UsePasswordConnectionInfoSection">
  66. <title>Use PasswordConnectionInfo to connect</title>
  67. <content>
  68. <para>
  69. To get more control over connection proccess when using username and password combination you need to use <codeEntityReference>T:Renci.SshNet.PasswordConnectionInfo</codeEntityReference> object.
  70. </para>
  71. <code language="cs" title="How to use PasswordConnectionInfo example">
  72. <![CDATA[
  73. var connectionInfo = new PasswordConnectionInfo("host", "username", "password");
  74. // Attach to connection event if needed here
  75. using (var client = new SftpClient(connectionInfo))
  76. {
  77. client.Connect();
  78. ...
  79. client.Disconnect();
  80. }
  81. ]]>
  82. </code>
  83. </content>
  84. </section>
  85. <section address="HandleExpiredPasswordSection">
  86. <title>Handle expired password</title>
  87. <content>
  88. <para>
  89. When user logs on and his password is expired you can ask user for a new passowrd and change it.
  90. <alert class="note">
  91. <para>The event handler will be executed on new thread</para>
  92. </alert>
  93. </para>
  94. <code language="cs" title="How to change expired password example">
  95. <![CDATA[
  96. var connectionInfo = new PasswordConnectionInfo("host", "username", "password");
  97. connectionInfo.PasswordExpired += delegate(object sender, AuthenticationPasswordChangeEventArgs e)
  98. {
  99. e.NewPassword = "123456";
  100. };
  101. using (var client = new SshClient(connectionInfo))
  102. {
  103. client.Connect();
  104. ....
  105. client.Disconnect();
  106. }
  107. ]]>
  108. </code>
  109. </content>
  110. </section>
  111. <relatedTopics>
  112. <codeEntityReference>T:Renci.SshNet.PasswordConnectionInfo</codeEntityReference>
  113. <codeEntityReference>T:Renci.SshNet.SshClient</codeEntityReference>
  114. <codeEntityReference>M:Renci.SshNet.SshBaseClient.Connect</codeEntityReference>
  115. </relatedTopics>
  116. </developerConceptualDocument>
  117. </topic>