I need to add ability for users to log in automaticly into web application with their windows user credentials. In application that I'm working on has the ability to login using your windows username and password. The way it works now is
a) user enters his windows username, password
b) With this info application tries to create DirectoryEntry and get NativeObject to ensure that info entered was valid.
String domainAndUsername = domain + @"\" + username;
DirectoryEntry entry = new DirectoryEntry(_path, domainAndUsername, pwd);
try
{ //Bind to the native AdsObject to force authentication.
DirectorySearcher search = new DirectorySearcher(entry2);
search.Filter = "(SAMAccountName=" + username + ")";
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();
if (null == result)
{
return false;
}
}
c) If this is succesful, app checks if any application users have this windows user specified as their windows username (windows username for each application user is saved in database table)
I'm pretty sure this article was used as an example for what is implemented:
http://support.microsoft.com/kb/326340
I can't figure out how to change this code so that I can look username in active direcoty without password.
Also I'm not used to dealing with Active Directory so if there is a easier/safer way to do the same thing please let me know.
allroy_
0 Points
1 Post
How to link users that are stored in db to windows users?
Nov 26, 2012 12:46 PM|LINK
Hi
I need to add ability for users to log in automaticly into web application with their windows user credentials. In application that I'm working on has the ability to login using your windows username and password. The way it works now is
a) user enters his windows username, password
b) With this info application tries to create DirectoryEntry and get NativeObject to ensure that info entered was valid.
String domainAndUsername = domain + @"\" + username; DirectoryEntry entry = new DirectoryEntry(_path, domainAndUsername, pwd); try { //Bind to the native AdsObject to force authentication. DirectorySearcher search = new DirectorySearcher(entry2); search.Filter = "(SAMAccountName=" + username + ")"; search.PropertiesToLoad.Add("cn"); SearchResult result = search.FindOne(); if (null == result) { return false; } }c) If this is succesful, app checks if any application users have this windows user specified as their windows username (windows username for each application user is saved in database table)
I'm pretty sure this article was used as an example for what is implemented:
http://support.microsoft.com/kb/326340
I can't figure out how to change this code so that I can look username in active direcoty without password.
Also I'm not used to dealing with Active Directory so if there is a easier/safer way to do the same thing please let me know.
Any suggestions are welcome.
css-chlukito
Member
412 Points
51 Posts
Re: How to link users that are stored in db to windows users?
Nov 29, 2012 09:04 AM|LINK
Hi,
Try another DirectoryEntry constructor as explained at below link:
http://msdn.microsoft.com/en-us/library/87tye19w.aspx
Please 'Mark as Answer' if this post helps you.