public void OnBeginRequest(object sender, EventArgs e) { Logging("::OnBeginRequest"); HttpApplication app = (HttpApplication)sender; HttpContext context = app.Context; string userid2; Initialize(sender); if (context.Request.IsAuthenticated) { Logging("Is Authenticated"); return; } string authorization = app.Request.Headers["Authorization"]; Logging("header: " + authorization ); #region base64 converter etc if ((authorization == null) || (authorization.Length == 0)) { Logging("BeginRequest: Authorization Header not present"); return; } if (authorization.StartsWith("NTLM") || authorization.StartsWith("Negotiate")) { int substringheader; if (authorization.StartsWith("Negotiate")) { substringheader = 10; Logging("BeginRequest: Headers Start with Negotiate"); }else { substringheader = 5; Logging("BeginRequest: Headers Start with NTLM"); } byte[] msg = Convert.FromBase64String(authorization.Substring(substringheader)); int off = 0, length, offset; if (msg[8] == 1) { Logging("BeginRequest:msg_offset_8 == 1"); } else if (msg[8] == 3) { Logging("BeginRequest:msg_offset_8 == 3 Header=" + authorization); //Encoding le = new UnicodeEncoding(false, true); // UTF-16LE off = 30; length = msg[off + 17] * 256 + msg[off + 16]; offset = msg[off + 19] * 256 + msg[off + 18]; String remoteHost = Encoding.Unicode.GetString(msg, offset, length); Logging("RemoteHost=" + remoteHost); length = msg[off + 1] * 256 + msg[off]; offset = msg[off + 3] * 256 + msg[off + 2]; String domain = Encoding.Unicode.GetString(msg, offset, length); Logging("Domain=" + domain); length = msg[off + 9] * 256 + msg[off + 8]; offset = msg[off + 11] * 256 + msg[off + 10]; userid2 = Encoding.Unicode.GetString(msg, offset, length); Logging("username="******"Starting Directory Mgmt Class"); ActiveDirectoryUser ADclsuser = new ActiveDirectoryUser(userid2, domain, notifydays); Logging("Constructed UPN: " + ADclsuser.constructedupn); if (ADclsuser.AccountExists()) { checkpassworddoesnotexpire = ADclsuser.PasswordDoesNotExpire(); checkpwdmustchange = ADclsuser.PasswordChangeRequired(); checkpwdexpired = ADclsuser.PasswordExpired(); checkpwdlokedout = ADclsuser.AccountLocked(); checkuseraccountstatus = ADclsuser.AccountDisabled(); Logging("Status: PasswordChangeRequired = " + checkpwdmustchange.ToString()); Logging("Status: PasswordExpired = " + checkpwdexpired.ToString()); Logging("Status: AccountLocked = " + checkpwdlokedout.ToString()); Logging("Status: AccountDisabled = " + checkuseraccountstatus.ToString()); } else { Logging("User " + ADclsuser.constructedupn + " does not exist"); return; } } } #endregion }
public void OnBeginRequest(object sender, EventArgs e) { Logging("::OnBeginRequest"); HttpApplication app = (HttpApplication)sender; HttpContext context = app.Context; string userid2; Initialize(sender); if (context.Request.IsAuthenticated) { Logging("Is Authenticated"); return; } string authorization = app.Request.Headers["Authorization"]; Logging("header: " + authorization); #region base64 converter etc if ((authorization == null) || (authorization.Length == 0)) { Logging("BeginRequest: Authorization Header not present"); return; } if (authorization.StartsWith("NTLM") || authorization.StartsWith("Negotiate")) { int substringheader; if (authorization.StartsWith("Negotiate")) { substringheader = 10; Logging("BeginRequest: Headers Start with Negotiate"); } else { substringheader = 5; Logging("BeginRequest: Headers Start with NTLM"); } byte[] msg = Convert.FromBase64String(authorization.Substring(substringheader)); int off = 0, length, offset; if (msg[8] == 1) { Logging("BeginRequest:msg_offset_8 == 1"); } else if (msg[8] == 3) { Logging("BeginRequest:msg_offset_8 == 3 Header=" + authorization); //Encoding le = new UnicodeEncoding(false, true); // UTF-16LE off = 30; length = msg[off + 17] * 256 + msg[off + 16]; offset = msg[off + 19] * 256 + msg[off + 18]; String remoteHost = Encoding.Unicode.GetString(msg, offset, length); Logging("RemoteHost=" + remoteHost); length = msg[off + 1] * 256 + msg[off]; offset = msg[off + 3] * 256 + msg[off + 2]; String domain = Encoding.Unicode.GetString(msg, offset, length); Logging("Domain=" + domain); length = msg[off + 9] * 256 + msg[off + 8]; offset = msg[off + 11] * 256 + msg[off + 10]; userid2 = Encoding.Unicode.GetString(msg, offset, length); Logging("username="******"Starting Directory Mgmt Class"); ActiveDirectoryUser ADclsuser = new ActiveDirectoryUser(userid2, domain, notifydays); Logging("Constructed UPN: " + ADclsuser.constructedupn); if (ADclsuser.AccountExists()) { checkpassworddoesnotexpire = ADclsuser.PasswordDoesNotExpire(); checkpwdmustchange = ADclsuser.PasswordChangeRequired(); checkpwdexpired = ADclsuser.PasswordExpired(); checkpwdlokedout = ADclsuser.AccountLocked(); checkuseraccountstatus = ADclsuser.AccountDisabled(); Logging("Status: PasswordChangeRequired = " + checkpwdmustchange.ToString()); Logging("Status: PasswordExpired = " + checkpwdexpired.ToString()); Logging("Status: AccountLocked = " + checkpwdlokedout.ToString()); Logging("Status: AccountDisabled = " + checkuseraccountstatus.ToString()); } else { Logging("User " + ADclsuser.constructedupn + " does not exist"); return; } } } #endregion }