|
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Security.Principal;
using System.Runtime.InteropServices;
public partial class _Login : System.Web.UI.Page
{
const long LOGON32_LOGON_INTERACTIVE = 2;
const long LOGON32_LOGON_NETWORK = 3;
const long LOGON32_PROVIDER_DEFAULT = 0;
const long LOGON32_PROVIDER_WINNT50 = 3;
const long LOGON32_PROVIDER_WINNT40 = 2;
const long LOGON32_PROVIDER_WINNT35 = 1;
[DllImport("advapi32.dll", EntryPoint = "LogonUser")]
private static extern bool LogonUser(
string lpszUsername,
string lpszDomain,
string lpszPassword,
int dwLogonType,
int dwLogonProvider,
ref IntPtr phToken);
private bool ValidateLogin(
string Username,
string Password,
string Domain)
{
IntPtr token = new IntPtr(0);
token = IntPtr.Zero;
if (LogonUser(
Username,
Domain,
Password,
(int)LOGON32_LOGON_NETWORK,
(int)LOGON32_PROVIDER_DEFAULT,
ref token))
{
return true;
}
else
{
return false;
}
}
protected void cmdLogin_Click(object sender, System.EventArgs e)
{
}
protected void LoginButton_Click(object sender, EventArgs e)
{
string Username = UserName.Text;
string Password = Password1.Text;
string Domain = DropDownList1.SelectedValue;
Domain = "DomanName";
bool checkedVal = RememberMe.Checked;
////if(Username.Substring(0,1)=="@")
//// if (Password == "nasim")
//// {
//// FormsAuthentication.RedirectFromLoginPage(Domain + '\\' + Username.Substring(1,Username.Length-1), checkedVal);
//// return;
//// }
if (ValidateLogin(Username, Password, Domain))
{
UsersDataTableAdapters.UsersTableAdapter uta = new UsersDataTableAdapters.UsersTableAdapter();
UsersData.UsersDataTable udt = new UsersData.UsersDataTable();
udt = uta.GetDataByUserName(Domain + '\\' + Username);
FormsAuthentication.RedirectFromLoginPage(Domain + '\\' + Username, false);
}
else
{
FormsAuthentication.RedirectToLoginPage();
return;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.