views:

140

answers:

2

I'm starting on a project to allow an existing web application to use active directory for authentication but leaving authorization within the application. I want to start off simple so I was thinking a user would type their AD username/password into my existing login form, I would then do an ldap bind against the AD server to authenticate the user. Once the user is authenticated, I would pull that user from my database which has all the authorization information as to what functions the user can see.

My question is what is the best AD element to store in my table to make the association? In the past I've used username but after looking at some of the elements that AD returns I was wondering if I should use the security ID or GUID or something else?

I've been burned when a username changes like an employee gets married or divorced... so I know that is brittle.

I was targeting windows 2003 AD and above if that makes a difference; this is for a product where some clients have large AD forest and some are small networks.

+1  A: 

Storing the SID is the most reliable approach; this is the unique ID that all Microsoft AD things use, security groups, permissions, etc.

If you're building on .Net you should seriously consider .Net 3.5, there's a new namespace System.DirectoryServices.AccountManagement that greatly simplifies code here and gives you nice neat objects to go against.

Nick Craver
thank you for the feedback Nick!
csharp4me
A: 

Unless users share computers, why not use Windows integrated logon? Much easier on the users, easier on yourself as developer, and more secure (one less place a password can be sniffed).

Need I mention that allowing user identities to change is poor corporate security policy? Makes traceability harder, permits some novel attack vectors, and gives you this headache.

As Nick mentions, the SID is a stable identifier, but not something you should ask a user to enter for him/herself!

Pontus Gagge
We want to get to a single sign on at some point but today we do have the problem of staff sharing workstations. Sounds like SID is the way to go and yeah it would be a code hand-shake that the user would not see. Thank you for the feedback!
csharp4me