CodeVerge.Net Beta


   Explore    Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums

MS SQL 2008 on ASP.NET Hosting



Zone: > NEWSGROUP > Asp.Net Forum > starter_kits_and_source_projects.portal_starter_kit Tags:
Item Type: NewsGroup Date Entered: 2/20/2003 2:00:03 AM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 4 Views: 50 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
5 Items, 1 Pages 1 |< << Go >> >|
cscott@ppi
Asp.Net User
Active Directory Authentication Code2/20/2003 2:00:03 AM

0/0

Here is my singin.ascx.vb file that uses AD for authentication. This function returns a 1 if the user is a valid AD user. I'm also working on getting the portal to use all of the groups from AD as well for security. Just replace the "Your Domain Here" with your domain, or add it to the submitting form and replace it with the form value.

*******Code for sigin.ascx.vb*******************
Imports System.Web.Security
Imports System
Imports System.Runtime.InteropServices
Imports System.Security.Principal
Imports System.Security.Permissions

Namespace ASPNetPortal

Public MustInherit Class Signin
Inherits ASPNetPortal.PortalModuleControl

Protected WithEvents email As System.Web.UI.WebControls.TextBox
Protected WithEvents password As System.Web.UI.WebControls.TextBox
Protected WithEvents RememberCheckbox As System.Web.UI.WebControls.CheckBox
Protected WithEvents SigninBtn As System.Web.UI.WebControls.ImageButton
Protected WithEvents Message As System.Web.UI.WebControls.Label

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region
<DllImport("advapi32.dll")> _
Public Shared Function LogonUser(ByVal lpszUsername As String, ByVal lpszDomain As String, ByVal lpszPassword As String, _
ByVal dwLogonType As Integer, ByVal dwLogonProvider As Integer, ByRef phToken As Integer) As Integer
End Function
Private Sub LoginBtn_Click(ByVal sender As Object, ByVal e As ImageClickEventArgs) Handles SigninBtn.Click

'New Authentication against Active Directory
'The Windows NT user token.
Dim intUserToken As Integer

'Get the user token for the specified user, machine, and password using the unmanaged LogonUser method.

'The parameters for LogonUser are the user name, computer name, password,
'Logon type (LOGON32_LOGON_NETWORK_CLEARTEXT), Logon provider (LOGON32_PROVIDER_DEFAULT),
'and user token.
Dim loggedOn As Integer = LogonUser(email.Text, "Your Domain Here", password.Text, 3, 0, intUserToken)

If loggedOn = 1 Then
FormsAuthentication.SetAuthCookie(email.Text, RememberCheckbox.Checked)
Response.Redirect(Request.ApplicationPath)
Else

Message.Text = "<" & "br" & ">Login Failed!" & "<" & "br" & ">"

End If

End Sub

End Class

End Namespace
**********************End of Code****************************

Enjoy,
Chris
jillykbean
Asp.Net User
Re: Active Directory Authentication Code5/19/2004 5:16:18 PM

0/0

I was able to use your example code (http://www.ibuyspy.com/Forums/ShowPost.aspx?tabindex=1&PostID=151708) in my Intranet portal, which allows users to authenticate to the Active Directory logging in via Forms authentication. However, my only problem now is that I can not access the Admin tab...

You had said that you were also working on getting the portal to use all of the groups from AD as well for security. Did you ever accomplish this? I can't seem to find the solution for this anywhere. I have established a security group for my portal administrators called PortalAdmin and have added members to this group. I realize somewhere I want to query the Domain\PortalAdmin but I can't figure out where to do this so that it works properly.

HELP PLEASE!!!

Thanks!
~Jill
:)
rlee0524
Asp.Net User
Re: Active Directory Authentication Code10/22/2004 7:54:57 PM

0/0

Jill,

I hope this helps in C#:

FileName: Authentication.cs

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.DirectoryServices;
using System.Web;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Security.Principal;
using System.Web.Security;
using Microsoft.ApplicationBlocks.ExceptionManagement;

public static bool AdAuthenticate(string username, string password,string path)
{
bool isAuthenticated = false;


DirectoryEntry userEntry = new DirectoryEntry(path,username,password);

try
{
DirectorySearcher dirSearcher = new DirectorySearcher(userEntry);

dirSearcher.Filter = "(SAMAccount=" + username + ")";
dirSearcher.PropertiesToLoad.Add("cn");
SearchResult searchResult = dirSearcher.FindOne();

isAuthenticated = true;

}
catch (Exception ex)
{
isAuthenticated = false;

// ignore logon failures do to incorrect password
// publish all other errors to the event log
if (ex.Message.Trim() != "Logon failure: unknown user name or bad password")
{

ExceptionManager.Publish(ex);
}
}

return isAuthenticated;
}


Now change the Signin.aspx.cs
Filename: Signin.aspx.cs

Change the LoginBtn_Click method:

....

private void LoginBtn_Click(Object sender, ImageClickEventArgs e) {

// Attempt to Validate User Credentials using UsersDB
UsersDB accountSystem = new UsersDB();
// Adding Active Directory Connectivity
string userId = "";

if (email.Text.ToLower() == "guest" || email.Text.ToLower() == "admin")
{
userId = accountSystem.Login(email.Text, password.Text);
}
else
{
userId = accountSystem.Login(email.Text,password.Text,true);
}

if ((userId != null) && (userId != "")) {

// Use security system to set the UserID within a client-side Cookie
FormsAuthentication.SetAuthCookie(email.Text, RememberCheckbox.Checked);

// Redirect browser back to originating page
Response.Redirect(Request.ApplicationPath);
}
else {
Message.Text = "<" + "br" + ">Login Failed!" + "<" + "br" + ">";
}
}

Note: I allow the guest and admin account to authenticate through the standard portal forms authentication.

You will also need the Microsoft Application Blocks Exception Management Patterns and Practices reference from their site to use ExceptionManager.Publish(ex).

Ryan Lee
[email protected]
lilon
Asp.Net User
Re: Active Directory Authentication Code11/11/2004 8:54:45 AM

0/0

I have posted the following question in the PSK forum and didnt get any response:

One of my Portal Starter Kit users (administrator) has asked me if the portal can use the windows active directory as the users backend authentication source, instead (or as base for) the sqlserver users table. His valid reason is that he doesnt want to maintain two users databases (active directory and the portal users table). This organisation uses the portal as an extranet (meaning I need uesrs from both within the domain as well as from outside, such as remote offices and mobile users access the extranet)

If I change the security setting in the web.config to Windows authentication instead of Forms authentication I get that effect, but then I lose the role based authorisation, which is essential for the portal.

Is there a way to use Windows authentication without losing the role based authorisation for accessing resources(tabs, and modules management level - view, edit etc)?
If the answer is yes, then how.

/////

It seems according to your solutions that you will be losing the possibility to create various roles dynamically in the portal because their role will not be reflected in the AD.
May I suggest another option: If we kept using the DB to authenticate users as well as assign their role, but used some kind of module (either in asp.net, script, or DTS (Data Transformation Services package through SQLServer)) that will periodically synchronise between the AD and the Users DB without dropping the roles for existing users (perhaps just automate copying of new accounts created in AD into the DB, assigning them default role. Optionally it could also, depending on the Administrator need, overwrite password changes in the AD into the DB).

I am happy to take role in this but I couldnt figure out how to communicate with the AD.

rlee0524
Asp.Net User
Re: Active Directory Authentication Code11/11/2004 2:19:04 PM

0/0

Using the code in my post prior to this you can access the AD by using a correct path:

LDAP://mail.<yourcompany>.com

WinNT://<computername>

read the microsoft article:

DirectoryEntry.Path Property
5 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
Active Directory: design and deployment of Microsoft's Active Directory Authors: Joe Richards, Robbie Allen, Alistair G. Lowe-Norris, Pages: 800, Published: 2006
Stealing the Network: How to Own the Box Authors: Ryan Russell, Jeff Moss, Pages: 448, Published: 2003
Mechanics of User Identification and Authentication: Fundamentals of Identity Management Authors: Dobromir Todorov, Pages: 728, Published: 2007
Mission-Critical Active Directory: Architecting a Secure and Scalable Infrastructure Authors: Micky Balladelli, Jan De Clercq, Pages: 640, Published: 2000
Building Secure Microsoft ASP.NET Applications: Authentication, Authorization, and Secure Communication : Patterns & Practices Authors: Microsoft Corporation Staff, Drew Bird, Microsoft Corporation, Microsoft Corporation, Danielle Voeller Bird, Pages: 586, Published: 2003
Pro WCF: Practical Microsoft SOA Implementation Authors: Chris Peiris, Dennis Mulder, Shawn Cicoria, Amit Bahree, Nishith Pathak, Pages: 475, Published: 2007
MCSA/MCSE: Windows Server 2003 Network Security Administration (70-299) Authors: Russ Kaufmann, Bill English, Pages: 608, Published: 2004
Active Directory Cookbook Authors: Robbie Allen, Laura E. Hunter, Pages: 962, Published: 2006
MCSE Windows Server 2003 Active Directory Infrastructure Study Guide (Exam 70-294): Study Guide (Exam 70-294) Authors: Dennis Suhanovs, Laura Robinson, Pages: 592, Published: 2003
Configuring Exchange 2000 Server Authors: Liz Mason, Elizabeth A Mason, ScienceDirect (Online service, Inc NetLibrary, William Lefkovitz, Syngress Publishing, William C Wade, Pages: 608, Published: 2001

Web:
Code Examples -> Authentication script to authenticate users in ... Code Example : Authentication script to authenticate users in Active Directory through LDAP.. Related Categories : LDAP, Authentication, Cookies, PHP.
Active Directory in C# and .NET - Tutorials, Articles, Resources ... This article and sample code explains how you can take advantage of Active Directory in Web applications for authenticate and authorize the Web site users. ...
Active Directory Authentication Code - ASP.NET Forums Re: Active Directory Authentication Code. 05-19-2004, 1:16 PM. Contact ... Re: Active Directory Authentication Code. 10-22-2004, 3:54 PM ...
Building Secure ASP.NET Applications: Authentication ... Configure the Web Application for Forms Authentication; Step 3.Develop LDAP Authentication Code to Look Up the User in Active Directory; Step 4. ...
CodeProject: Authentication against Active Directory and ... An article on authenticating user against Active Directory and Edirectory; Author: Abdul (Rajib) Bahar; Section: Hardware & System; Chapter: General ...
Web Services Security - HTTP Basic Authentication without Active ... Web Services Security - HTTP Basic Authentication without Active Directory. June 26th, 2002 by gregr .NET HTTP Module - sample code ...
WordPress › Support » [Plugin: Active Directory Authentication ... [Plugin: Active Directory Authentication] please remove php_short_tags from the code (2 posts). intersol Member Posted 1 month ago # ...
Using Forms Authentication with Active Directory Now it is time to implement the active directory authentication code. You will create a new class that will provide a method that receives a domain name, ...
HOWTO: Active Directory Authentication - Ubuntu Forums HOWTO: Active Directory Authentication Tutorials & Tips. ... 2) See the Active Directory SID for a particular named user. Code:. wbinfo –n ...
Active Directory Authentication Code - ASP.NET Forums Active Directory Authentication Code. Last post 11-11-2004 10:21 AM by rlee0524. 4 replies. Sort Posts:. Oldest to newest, Newest to oldest ...

Videos:
Access .Net Active Directory from C#, VB.Net Code Add users to Active Directory, authenticate a user, etc.
How to Video: Using Active Directory Searching/Lookup in a S This is the eighth in a series (the series is listed at the bottom) of "How To " Videos that I have created to show .NET Developers how to build docu...
Shmoo1847 EoinMiller &Adair Collings - Auditing Cached Credential With Cachedump Recorded at the www.ShmooCon.org HACKING AND COMPUTER SECURITY CONFERENCE, March 23, 2007 in Washington, D.C. Content produced by www.MediaArchives.c...
How to: Search Active Directory with .NET "How-to" program AD with .NET, in which I show you how to search AD for objects, like users, groups, printers, etc. You can find a high-def version ...
How to: Add a user to Active Directory with .NET In this video I take you through a 10 minute walkthrough/demonstation of how to add a user and set the users Active Directory properties with .NET (C...
Owasp5013 - Dinis Cruz1 - Building A Tool For Security Consultants Recorded at the Open Web Application Security Project (www.OWASP.org) NYC Conference on Sep 25, 2008 – Content produced by www.MediaArchives.com - Ma...
How to: Adding users to groups in Active Directory with .NET In this video I take you through a 8 minute walkthrough/demonstration of how to create a group in active directory with .NET and to add users to that...
Inside Scripting - VBScript, WMI and ADSI Unleashed Don Jones discusses his latest book, VBScript, WMI, and ADSI Unleashed: Using VBScript, WMI, and ADSI to Automate Windows® Administration, 2nd Editio...
Tech_Show Episode 7 Tech_Show Episode 7 ASSOC we did not say. Command Prompt Commands: ASSOC-Displays or modifies file extension associations. ATTRIB-Displays or change...
A Googly MySQL Cluster Talk Google TechTalks April 28, 2006 Stewart Smith Stewart Smith works for MySQL AB as a software engineer working on MySQL Cluster. He is an active memb...




Search This Site:










installation guide for dummies,

can't login as admin

dotnetnuke 2.04 xml/xsl module issue

need help with webcontrols source code asap

moving ddn

module with 5 o more view control

dnn 2.1.2: looses authentication when clicking on link

blank page after logon in ie.

htmldecode a dropdownlist

dnn vacation

datagrid sorting in c#

how to get rid of the white separator lines in solpart submenu..?!?

solpartmenu postback menuclick event

check if current user is admin?

dotnetnuke vs project hurricane?

forumblog_03[1].10.01_install zip installation?

creating an add update delete table for dnn 2b2

suddenly cannot login

"personalisation store "... where / what is it...

multiple panes in dnn?

problems with tttgallery

just a laugh

converting webpages to dnn

problems with dnn 3.1.1 with rich text editor & bonosoft multipage module 3.03

how to expose a dotnetnuke module in dnn3.1.1 as a webservice.

vb to c# converter

creating dotnetnuke multipage modules

dnn 3.0.13 error - clean instalation

module edit option disapeared???

open file manager to particular directory

  Privacy | Contact Us
All Times Are GMT