/// <summary> /// The constructor with the fully qualified username and password combined /// string argument. /// </summary> /// <remarks> /// The constructor with the fully qualified username and password combined /// string argument. /// </remarks> /// <param name="usernamePassword">the domain/username:password formed string</param> public NTCredentials(string usernamePassword) : base() { Args.NotNull(usernamePassword, "Username:password string"); string username; int atColon = usernamePassword.IndexOf(':'); if (atColon >= 0) { username = Sharpen.Runtime.Substring(usernamePassword, 0, atColon); this.password = Sharpen.Runtime.Substring(usernamePassword, atColon + 1); } else { username = usernamePassword; this.password = null; } int atSlash = username.IndexOf('/'); if (atSlash >= 0) { this.principal = new NTUserPrincipal(Sharpen.Runtime.Substring(username, 0, atSlash ).ToUpper(Sharpen.Extensions.GetEnglishCulture()), Sharpen.Runtime.Substring(username , atSlash + 1)); } else { this.principal = new NTUserPrincipal(null, Sharpen.Runtime.Substring(username, atSlash + 1)); } this.workstation = null; }
/// <summary>Constructor.</summary> /// <remarks>Constructor.</remarks> /// <param name="userName"> /// The user name. This should not include the domain to authenticate with. /// For example: "user" is correct whereas "DOMAIN\\user" is not. /// </param> /// <param name="password">The password.</param> /// <param name="workstation"> /// The workstation the authentication request is originating from. /// Essentially, the computer name for this machine. /// </param> /// <param name="domain">The domain to authenticate within.</param> public NTCredentials(string userName, string password, string workstation, string domain) : base() { Args.NotNull(userName, "User name"); this.principal = new NTUserPrincipal(domain, userName); this.password = password; if (workstation != null) { this.workstation = workstation.ToUpper(Sharpen.Extensions.GetEnglishCulture()); } else { this.workstation = null; } }