Click here to Skip to main content
11,922,641 members (57,986 online)
Click here to Skip to main content
Add your own
alternative version


25 bookmarked

Forms Authentication Without Password In ASP.NET

, 9 Sep 2007 CPOL
Rate this:
Please Sign up or sign in to vote.
Mixed Mode Of Windows authentication And Forms authentication


Password Protection And Password Management is an important issue In designing Control System Or Other Authorizing Permissins system.

  • Some Developer Using The Encryption Algoritms To Encrypt Password Before Saving In Database And Save The Encrypted Password In DataBase And Encryption Password And Decryption Made By Application Layer.
    This is Useful When We have A Complex Authorization In Access To Permissins therefore When Hacker hacked our Database It is Difficult to to befool us like change the permissions and other...
  • It is Difficult to users To record Password for several system and users like have one or two password for logining systems.


In This Article we Use The Mixed Mode Authentication(Forms and Windows) For Loggining Systems This Is Use full To Managing Security In Intranet System Because the NT Security In Manage The security Of Our System and NT Security in Windows successfully In Managing Security

Using the code

Before We Use the Code We Ust Go To the ComputerManageMent Of Server(or your system)
and then go to Groups And Users And Define the ASP.Net As Member Of System Worker
or Act as part of the operating system

  1. Configure your Web application's web.config file to use Forms Authentication
    <authentication mode="Forms">
    	<!--<forms loginUrl="Login.aspx" cookieless="UseUri" slidingExpiration="true" 
    		name=".LogonUserDemo2" timeout="20" path="/" protection="All"/>-->
    	<allow users="*"/>
    <location path="Secured Folder" >
    			<deny users="?"/>
  2. Create your login page :

    Important point In Login Page Define the Api that Using The Windows Security

    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(
    			ref token))
    			return true;
    			return false;

    After checking User If Exists In Our Domain We Check User That Exising In Our Users Database and The Permissins For them.

    	string Username = UserName.Text;
    	string Password = Password1.Text;
    	string Domain = DropDownList1.SelectedValue;
    	Domain = "DomanName";
    	bool checkedVal = RememberMe.Checked;
    	//// 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);

Points of Interest

Exactly I use The Resource About Definition of api From Internet And MSDN.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

hooshang Karami
Web Developer
Iran (Islamic Republic Of) Iran (Islamic Republic Of)
i am programmer and i am programming 10 year
I am VB Progarammer Webdevelpoer Intranet Site Developer Programmer
in SqlServer DatabAse
I am Developing Accounting System And Sell Systems
In C# Or In SqlServer 2000 ,
I like Programming And I live With Programming
iran tehran

You may also be interested in...

Comments and Discussions

GeneralNot sure Pin
Jan Seda10-Sep-07 6:14
memberJan Seda10-Sep-07 6:14 
GeneralRe: Not sure Pin
hooshang Karami10-Sep-07 19:55
memberhooshang Karami10-Sep-07 19:55 
GeneralRe: Not sure Pin
Jan Seda10-Sep-07 21:47
memberJan Seda10-Sep-07 21:47 
GeneralRe: Not sure Pin
hooshang Karami11-Sep-07 1:25
memberhooshang Karami11-Sep-07 1:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.151125.1 | Last Updated 10 Sep 2007
Article Copyright 2007 by hooshang Karami
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid