< Summary

Information
Class: Renci.SshNet.PasswordConnectionInfo
Assembly: Renci.SshNet
File(s): \home\appveyor\projects\ssh-net\src\Renci.SshNet\PasswordConnectionInfo.cs
Line coverage
48%
Covered lines: 39
Uncovered lines: 42
Coverable lines: 81
Total lines: 313
Line coverage: 48.1%
Branch coverage
81%
Covered branches: 13
Total branches: 16
Branch coverage: 81.2%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor(...)100%133.33%
.ctor(...)100%1100%
.ctor(...)100%10%
.ctor(...)100%10%
.ctor(...)100%10%
.ctor(...)100%10%
.ctor(...)100%10%
.ctor(...)100%10%
.ctor(...)100%133.33%
.ctor(...)100%10%
.ctor(...)100%10%
.ctor(...)100%10%
.ctor(...)100%10%
.ctor(...)100%10%
.ctor(...)100%4100%
AuthenticationMethod_PasswordExpired(...)0%20%
Dispose()100%1100%
Dispose(...)90%1089.47%
Finalize()100%1100%

File(s)

\home\appveyor\projects\ssh-net\src\Renci.SshNet\PasswordConnectionInfo.cs

#LineLine coverage
 1using System;
 2using System.Net;
 3using System.Text;
 4using Renci.SshNet.Common;
 5
 6namespace Renci.SshNet
 7{
 8    /// <summary>
 9    /// Provides connection information when password authentication method is used.
 10    /// </summary>
 11    /// <example>
 12    ///     <code source="..\..\src\Renci.SshNet.Tests\Classes\PasswordConnectionInfoTest.cs" region="Example PasswordCo
 13    ///     <code source="..\..\src\Renci.SshNet.Tests\Classes\PasswordConnectionInfoTest.cs" region="Example PasswordCo
 14    ///     <code source="..\..\src\Renci.SshNet.Tests\Classes\PasswordConnectionInfoTest.cs" region="Example PasswordCo
 15    /// </example>
 16    public class PasswordConnectionInfo : ConnectionInfo, IDisposable
 17    {
 18        private bool _isDisposed;
 19
 20        /// <summary>
 21        /// Occurs when user's password has expired and needs to be changed.
 22        /// </summary>
 23        /// <example>
 24        ///     <code source="..\..\src\Renci.SshNet.Tests\Classes\PasswordConnectionInfoTest.cs" region="Example Passwo
 25        /// </example>
 26        public event EventHandler<AuthenticationPasswordChangeEventArgs> PasswordExpired;
 27
 28        /// <summary>
 29        /// Initializes a new instance of the <see cref="PasswordConnectionInfo" /> class.
 30        /// </summary>
 31        /// <param name="host">Connection host.</param>
 32        /// <param name="username">Connection username.</param>
 33        /// <param name="password">Connection password.</param>
 34        /// <example>
 35        ///     <code source="..\..\src\Renci.SshNet.Tests\Classes\PasswordConnectionInfoTest.cs" region="Example Passwo
 36        /// </example>
 37        /// <exception cref="ArgumentNullException"><paramref name="password"/> is <see langword="null"/>.</exception>
 38        /// <exception cref="ArgumentException"><paramref name="host"/> is invalid, or <paramref name="username"/> is <s
 39        public PasswordConnectionInfo(string host, string username, string password)
 1240            : this(host, DefaultPort, username, Encoding.UTF8.GetBytes(password))
 041        {
 042        }
 43
 44        /// <summary>
 45        /// Initializes a new instance of the <see cref="PasswordConnectionInfo"/> class.
 46        /// </summary>
 47        /// <param name="host">Connection host.</param>
 48        /// <param name="port">Connection port.</param>
 49        /// <param name="username">Connection username.</param>
 50        /// <param name="password">Connection password.</param>
 51        /// <exception cref="ArgumentNullException"><paramref name="password"/> is <see langword="null"/>.</exception>
 52        /// <exception cref="ArgumentException"><paramref name="host"/> is invalid, or <paramref name="username"/> is <s
 53        /// <exception cref="ArgumentOutOfRangeException"><paramref name="port"/> is not within <see cref="IPEndPoint.Mi
 54        public PasswordConnectionInfo(string host, int port, string username, string password)
 23155            : this(host, port, username, Encoding.UTF8.GetBytes(password), ProxyTypes.None, string.Empty, 0, string.Empt
 22556        {
 22557        }
 58
 59        /// <summary>
 60        /// Initializes a new instance of the <see cref="PasswordConnectionInfo"/> class.
 61        /// </summary>
 62        /// <param name="host">Connection host.</param>
 63        /// <param name="port">The port.</param>
 64        /// <param name="username">Connection username.</param>
 65        /// <param name="password">Connection password.</param>
 66        /// <param name="proxyType">Type of the proxy.</param>
 67        /// <param name="proxyHost">The proxy host.</param>
 68        /// <param name="proxyPort">The proxy port.</param>
 69        public PasswordConnectionInfo(string host, int port, string username, string password, ProxyTypes proxyType, str
 070            : this(host, port, username, Encoding.UTF8.GetBytes(password), proxyType, proxyHost, proxyPort, string.Empty
 071        {
 072        }
 73
 74        /// <summary>
 75        /// Initializes a new instance of the <see cref="PasswordConnectionInfo"/> class.
 76        /// </summary>
 77        /// <param name="host">Connection host.</param>
 78        /// <param name="port">The port.</param>
 79        /// <param name="username">Connection username.</param>
 80        /// <param name="password">Connection password.</param>
 81        /// <param name="proxyType">Type of the proxy.</param>
 82        /// <param name="proxyHost">The proxy host.</param>
 83        /// <param name="proxyPort">The proxy port.</param>
 84        /// <param name="proxyUsername">The proxy username.</param>
 85        public PasswordConnectionInfo(string host, int port, string username, string password, ProxyTypes proxyType, str
 086            : this(host, port, username, Encoding.UTF8.GetBytes(password), proxyType, proxyHost, proxyPort, proxyUsernam
 087        {
 088        }
 89
 90        /// <summary>
 91        /// Initializes a new instance of the <see cref="PasswordConnectionInfo"/> class.
 92        /// </summary>
 93        /// <param name="host">Connection host.</param>
 94        /// <param name="username">Connection username.</param>
 95        /// <param name="password">Connection password.</param>
 96        /// <param name="proxyType">Type of the proxy.</param>
 97        /// <param name="proxyHost">The proxy host.</param>
 98        /// <param name="proxyPort">The proxy port.</param>
 99        public PasswordConnectionInfo(string host, string username, string password, ProxyTypes proxyType, string proxyH
 0100            : this(host, DefaultPort, username, Encoding.UTF8.GetBytes(password), proxyType, proxyHost, proxyPort, strin
 0101        {
 0102        }
 103
 104        /// <summary>
 105        /// Initializes a new instance of the <see cref="PasswordConnectionInfo"/> class.
 106        /// </summary>
 107        /// <param name="host">Connection host.</param>
 108        /// <param name="username">Connection username.</param>
 109        /// <param name="password">Connection password.</param>
 110        /// <param name="proxyType">Type of the proxy.</param>
 111        /// <param name="proxyHost">The proxy host.</param>
 112        /// <param name="proxyPort">The proxy port.</param>
 113        /// <param name="proxyUsername">The proxy username.</param>
 114        public PasswordConnectionInfo(string host, string username, string password, ProxyTypes proxyType, string proxyH
 0115            : this(host, DefaultPort, username, Encoding.UTF8.GetBytes(password), proxyType, proxyHost, proxyPort, proxy
 0116        {
 0117        }
 118
 119        /// <summary>
 120        /// Initializes a new instance of the <see cref="PasswordConnectionInfo"/> class.
 121        /// </summary>
 122        /// <param name="host">Connection host.</param>
 123        /// <param name="username">Connection username.</param>
 124        /// <param name="password">Connection password.</param>
 125        /// <param name="proxyType">Type of the proxy.</param>
 126        /// <param name="proxyHost">The proxy host.</param>
 127        /// <param name="proxyPort">The proxy port.</param>
 128        /// <param name="proxyUsername">The proxy username.</param>
 129        /// <param name="proxyPassword">The proxy password.</param>
 130        public PasswordConnectionInfo(string host, string username, string password, ProxyTypes proxyType, string proxyH
 0131            : this(host, DefaultPort, username, Encoding.UTF8.GetBytes(password), proxyType, proxyHost, proxyPort, proxy
 0132        {
 0133        }
 134
 135        /// <summary>
 136        /// Initializes a new instance of the <see cref="PasswordConnectionInfo"/> class.
 137        /// </summary>
 138        /// <param name="host">Connection host.</param>
 139        /// <param name="username">Connection username.</param>
 140        /// <param name="password">Connection password.</param>
 141        public PasswordConnectionInfo(string host, string username, byte[] password)
 0142            : this(host, DefaultPort, username, password)
 0143        {
 0144        }
 145
 146        /// <summary>
 147        /// Initializes a new instance of the <see cref="PasswordConnectionInfo" /> class.
 148        /// </summary>
 149        /// <param name="host">Connection host.</param>
 150        /// <param name="port">Connection port.</param>
 151        /// <param name="username">Connection username.</param>
 152        /// <param name="password">Connection password.</param>
 153        /// <exception cref="ArgumentNullException"><paramref name="password" /> is <see langword="null"/>.</exception>
 154        /// <exception cref="ArgumentException"><paramref name="host" /> is invalid, or <paramref name="username" /> is 
 155        /// <exception cref="ArgumentOutOfRangeException"><paramref name="port" /> is not within <see cref="IPEndPoint.M
 156        public PasswordConnectionInfo(string host, int port, string username, byte[] password)
 9157            : this(host, port, username, password, ProxyTypes.None, string.Empty, 0, string.Empty, string.Empty)
 0158        {
 0159        }
 160
 161        /// <summary>
 162        /// Initializes a new instance of the <see cref="PasswordConnectionInfo"/> class.
 163        /// </summary>
 164        /// <param name="host">Connection host.</param>
 165        /// <param name="port">The port.</param>
 166        /// <param name="username">Connection username.</param>
 167        /// <param name="password">Connection password.</param>
 168        /// <param name="proxyType">Type of the proxy.</param>
 169        /// <param name="proxyHost">The proxy host.</param>
 170        /// <param name="proxyPort">The proxy port.</param>
 171        public PasswordConnectionInfo(string host, int port, string username, byte[] password, ProxyTypes proxyType, str
 0172            : this(host, port, username, password, proxyType, proxyHost, proxyPort, string.Empty, string.Empty)
 0173        {
 0174        }
 175
 176        /// <summary>
 177        /// Initializes a new instance of the <see cref="PasswordConnectionInfo"/> class.
 178        /// </summary>
 179        /// <param name="host">Connection host.</param>
 180        /// <param name="port">The port.</param>
 181        /// <param name="username">Connection username.</param>
 182        /// <param name="password">Connection password.</param>
 183        /// <param name="proxyType">Type of the proxy.</param>
 184        /// <param name="proxyHost">The proxy host.</param>
 185        /// <param name="proxyPort">The proxy port.</param>
 186        /// <param name="proxyUsername">The proxy username.</param>
 187        public PasswordConnectionInfo(string host, int port, string username, byte[] password, ProxyTypes proxyType, str
 0188            : this(host, port, username, password, proxyType, proxyHost, proxyPort, proxyUsername, string.Empty)
 0189        {
 0190        }
 191
 192        /// <summary>
 193        /// Initializes a new instance of the <see cref="PasswordConnectionInfo"/> class.
 194        /// </summary>
 195        /// <param name="host">Connection host.</param>
 196        /// <param name="username">Connection username.</param>
 197        /// <param name="password">Connection password.</param>
 198        /// <param name="proxyType">Type of the proxy.</param>
 199        /// <param name="proxyHost">The proxy host.</param>
 200        /// <param name="proxyPort">The proxy port.</param>
 201        public PasswordConnectionInfo(string host, string username, byte[] password, ProxyTypes proxyType, string proxyH
 0202            : this(host, DefaultPort, username, password, proxyType, proxyHost, proxyPort, string.Empty, string.Empty)
 0203        {
 0204        }
 205
 206        /// <summary>
 207        /// Initializes a new instance of the <see cref="PasswordConnectionInfo"/> class.
 208        /// </summary>
 209        /// <param name="host">Connection host.</param>
 210        /// <param name="username">Connection username.</param>
 211        /// <param name="password">Connection password.</param>
 212        /// <param name="proxyType">Type of the proxy.</param>
 213        /// <param name="proxyHost">The proxy host.</param>
 214        /// <param name="proxyPort">The proxy port.</param>
 215        /// <param name="proxyUsername">The proxy username.</param>
 216        public PasswordConnectionInfo(string host, string username, byte[] password, ProxyTypes proxyType, string proxyH
 0217            : this(host, DefaultPort, username, password, proxyType, proxyHost, proxyPort, proxyUsername, string.Empty)
 0218        {
 0219        }
 220
 221        /// <summary>
 222        /// Initializes a new instance of the <see cref="PasswordConnectionInfo"/> class.
 223        /// </summary>
 224        /// <param name="host">Connection host.</param>
 225        /// <param name="username">Connection username.</param>
 226        /// <param name="password">Connection password.</param>
 227        /// <param name="proxyType">Type of the proxy.</param>
 228        /// <param name="proxyHost">The proxy host.</param>
 229        /// <param name="proxyPort">The proxy port.</param>
 230        /// <param name="proxyUsername">The proxy username.</param>
 231        /// <param name="proxyPassword">The proxy password.</param>
 232        public PasswordConnectionInfo(string host, string username, byte[] password, ProxyTypes proxyType, string proxyH
 0233            : this(host, DefaultPort, username, password, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword)
 0234        {
 0235        }
 236
 237        /// <summary>
 238        /// Initializes a new instance of the <see cref="PasswordConnectionInfo"/> class.
 239        /// </summary>
 240        /// <param name="host">Connection host.</param>
 241        /// <param name="port">The port.</param>
 242        /// <param name="username">Connection username.</param>
 243        /// <param name="password">Connection password.</param>
 244        /// <param name="proxyType">Type of the proxy.</param>
 245        /// <param name="proxyHost">The proxy host.</param>
 246        /// <param name="proxyPort">The proxy port.</param>
 247        /// <param name="proxyUsername">The proxy username.</param>
 248        /// <param name="proxyPassword">The proxy password.</param>
 249        public PasswordConnectionInfo(string host, int port, string username, byte[] password, ProxyTypes proxyType, str
 240250            : base(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword, new PasswordAuth
 225251        {
 1125252            foreach (var authenticationMethod in AuthenticationMethods)
 225253            {
 225254                if (authenticationMethod is PasswordAuthenticationMethod pwdAuthentication)
 225255                {
 225256                    pwdAuthentication.PasswordExpired += AuthenticationMethod_PasswordExpired;
 225257                }
 225258            }
 225259        }
 260
 261        private void AuthenticationMethod_PasswordExpired(object sender, AuthenticationPasswordChangeEventArgs e)
 0262        {
 263#pragma warning disable MA0091 // Sender should be 'this' for instance events
 0264            PasswordExpired?.Invoke(sender, e);
 265#pragma warning restore MA0091 // Sender should be 'this' for instance events
 0266        }
 267
 268        /// <summary>
 269        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 270        /// </summary>
 271        public void Dispose()
 174272        {
 174273            Dispose(disposing: true);
 174274            GC.SuppressFinalize(this);
 174275        }
 276
 277        /// <summary>
 278        /// Releases unmanaged and - optionally - managed resources.
 279        /// </summary>
 280        /// <param name="disposing"><see langword="true"/> to release both managed and unmanaged resources; <see langwor
 281        protected virtual void Dispose(bool disposing)
 243282        {
 243283            if (_isDisposed)
 0284            {
 0285                return;
 286            }
 287
 243288            if (disposing)
 174289            {
 174290                if (AuthenticationMethods != null)
 174291                {
 870292                    foreach (var authenticationMethod in AuthenticationMethods)
 174293                    {
 174294                        if (authenticationMethod is IDisposable disposable)
 174295                        {
 174296                            disposable.Dispose();
 174297                        }
 174298                    }
 174299                }
 300
 174301                _isDisposed = true;
 174302            }
 243303        }
 304
 305        /// <summary>
 306        /// Finalizes an instance of the <see cref="PasswordConnectionInfo"/> class.
 307        /// </summary>
 308        ~PasswordConnectionInfo()
 138309        {
 69310            Dispose(disposing: false);
 138311        }
 312    }
 313}

Methods/Properties

.ctor(System.String,System.String,System.String)
.ctor(System.String,System.Int32,System.String,System.String)
.ctor(System.String,System.Int32,System.String,System.String,Renci.SshNet.ProxyTypes,System.String,System.Int32)
.ctor(System.String,System.Int32,System.String,System.String,Renci.SshNet.ProxyTypes,System.String,System.Int32,System.String)
.ctor(System.String,System.String,System.String,Renci.SshNet.ProxyTypes,System.String,System.Int32)
.ctor(System.String,System.String,System.String,Renci.SshNet.ProxyTypes,System.String,System.Int32,System.String)
.ctor(System.String,System.String,System.String,Renci.SshNet.ProxyTypes,System.String,System.Int32,System.String,System.String)
.ctor(System.String,System.String,System.Byte[])
.ctor(System.String,System.Int32,System.String,System.Byte[])
.ctor(System.String,System.Int32,System.String,System.Byte[],Renci.SshNet.ProxyTypes,System.String,System.Int32)
.ctor(System.String,System.Int32,System.String,System.Byte[],Renci.SshNet.ProxyTypes,System.String,System.Int32,System.String)
.ctor(System.String,System.String,System.Byte[],Renci.SshNet.ProxyTypes,System.String,System.Int32)
.ctor(System.String,System.String,System.Byte[],Renci.SshNet.ProxyTypes,System.String,System.Int32,System.String)
.ctor(System.String,System.String,System.Byte[],Renci.SshNet.ProxyTypes,System.String,System.Int32,System.String,System.String)
.ctor(System.String,System.Int32,System.String,System.Byte[],Renci.SshNet.ProxyTypes,System.String,System.Int32,System.String,System.String)
AuthenticationMethod_PasswordExpired(System.Object,Renci.SshNet.Common.AuthenticationPasswordChangeEventArgs)
Dispose()
Dispose(System.Boolean)
Finalize()