LDAP Authentication .Net 1.0 code to .Net 2.0

A few years ago with help of Dunry (I think he wrote most of the LDAP part) we came up with the below C# that works in our environment. We now need to migrate this to .Net 2.0.

Does anyone have any examples of something simliar that works in .Net 2.0?

Thanks in advance.

private void btnSubmit_Click(object sender, System.EventArgs e)
  {
   if(Page.IsValid)
   {
    SearchDirectoryUsername(txtUsername.Text);
   }
  }

  private void SearchDirectoryUsername(string username)
  {
   using (DirectoryEntry de = new DirectoryEntry(ConfigurationSettings.AppSettings["ldapaddress"] + ConfigurationSettings.AppSettings["ldapbasepath"]))
   using (DirectorySearcher searcher = new DirectorySearcher())
   {
    searcher.SearchRoot = de;
    searcher.Filter = "(uid=" + txtUsername.Text.ToString() + ")";
    searcher.SearchScope = SearchScope.Subtree;
    searcher.PropertiesToLoad.Add("mail");  
    searcher.PropertiesToLoad.Add("givenname");
    searcher.PropertiesToLoad.Add("sn");
   
    searcher.Sort = new SortOption("mail", SortDirection.Ascending);

    SearchResultCollection results = searcher.FindAll();
    
    foreach (SearchResult result in results)
    {
     ResultPropertyCollection props = result.Properties;
     string Email = props["mail"][0].ToString();
     string Name = props["givenname"][0].ToString() + " " + props["sn"][0].ToString();
     string UserDN = result.Path.Replace(ConfigurationSettings.AppSettings["ldapaddress"],"");
     AuthenticateUser(UserDN,Email,Name);     
    }    
   }   
  }

  
  private void AuthenticateUser(string UserDN, string Email, String Name)
  {    
   string password = txtPassword.Text;   
   DirectoryEntry de = new DirectoryEntry(ConfigurationSettings.AppSettings["ldapaddress"] + UserDN);
   de.AuthenticationType = AuthenticationTypes.None;
   de.Username = UserDN;
   de.Password = password;

   try
   {
    string name = de.Name; //force a bind  
    de.RefreshCache();
    lblMessage.Text = "Success, You have been authenticated.";
    EncryptEmail(UserDN, Email, Name);
   }

   catch(Exception ex)

   {
    lblMessage.CssClass = "Error";
    lblMessage.Text = "Failure: " + ex.Message;
   }

   finally

   {
    de.Close();
   }

  }
 

  private void EncryptEmail(string username, string Email, string Name)
  {
   String gKey = "5678321";
   String gstrSource = Email;
   
   FE_Symmetric feService = new FE_Symmetric();

   String EncryptedEmail;   
   
   EncryptedEmail = feService.EncryptData(gKey, gstrSource);
   
   CreateTicket(username, EncryptedEmail, Name);
   //DecryptEmail(strEncryptedEmail);  
  }

  private void CreateTicket(string username, string EncryptedEmail, string Name)
  {
   string userData = "ApplicationSpecific data for this user.";
    

   FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
    1,
    username,
    System.DateTime.Now,
    System.DateTime.Now.AddMinutes(Convert.ToDouble(ConfigurationSettings.AppSettings["CookieExpiry"])),
    false,
    userData,
    FormsAuthentication.FormsCookiePath);

    
   // Encrypt the ticket.
   string encTicket = FormsAuthentication.Encrypt(ticket);

   // Create the cookie.
   Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket));
    
   HttpCookie cookie = new HttpCookie("E", EncryptedEmail); 
   cookie.Expires = DateTime.Now.AddMinutes(500);
   Response.Cookies.Add(cookie);
             
  
   

   // Redirect back to original URL.
   Response.Redirect(FormsAuthentication.GetRedirectUrl(username,false));
  }
  


Regards

Nick
0
riggers
8/30/2006 7:14:01 AM
asp.net.active-directory-ldap 2291 articles. 0 followers. Follow

2 Replies
944 Views

Similar Articles

[PageSpeed] 26

Looking at the code further the error appears in the bind being:

  try
   {
    string name = de.Name; //force a bind  
    de.RefreshCache();
    lblMessage.Text = "Success, You have been authenticated.";
    EncryptEmail(UserDN, Email, Name);
   }

 Searching the LDAP appears to be completely fine.

Any ideas anyone?

 


Regards

Nick
0
riggers
8/30/2006 4:58:14 PM
Download the sample code to my book - a link to it is posted on top this forum - and check Ch. 12's samples for authentication.
Ryan Dunn
Weblog
The Book
LDAP Programming Help
0
dunnry
8/31/2006 5:11:53 PM
Reply:

Similar Artilces:

Differences between .net 1, .net 1.1, .net 2.0 and .net 3.0 #2
Hi, This seems to be a common question, but i havent got an answer yet:(Can, any one please explain me the differences between these versions.If you keep your feet firmly on the ground, you'll have trouble putting on your pants! There are too many differences for one email - - from 1.0 to 1.1 (not a whole lot of real change, other than fixes, at least compared to 1.1 to 2.0) With 2.0, there were many new declarative controls, with many new ideas added in With 3.0, it's a superset of 2.0 - instead of replacing the installation completely, it just 'added on' new functionality - I would...

Differences between .net 1, .net 1.1, .net 2.0 and .net 3.0
Hi, This seems to be a common question, but i havent got an answer yet:(Can, any one please explain me the differences between these versions.If you keep your feet firmly on the ground, you'll have trouble putting on your pants! Have a look into this links http://en.wikipedia.org/wiki/.NET_Framework http://blogs.msdn.com/mohammadakif/archive/2006/12/03/net-3-0-different-versions-of-the-net-framework.aspx http://www.codeproject.com/aspnet/ComparisonASP1xASP20.aspAshok Rajawww.iGold.inDon't forget to click "Mark as Answer" on the post that helped you. This credits that m...

Code works with .Net 1.1 but not .Net 2.0
Can anyone offer any suggestions as to why this code would work under .Net 1.1 and not .Net 2.0? I listed the error I receive below, also. Line 865. Thank you, Public Function GetAge(ByVal Birthdate As System.DateTime, _ Optional ByVal AsOf As System.DateTime = #1/1/1700#) _ As Integer Dim iMonths As Integer Dim iYears As Integer Dim dYears As Decimal Dim lDayOfBirth As Long Dim lAsOf As Long Dim iBirthMonth As Integer Dim iAsOFMonth As Integer If AsOf = "#1/1/1700#" ...

Where is the ADO.NET Sybase driver for .NET 1.1 and .Net 2.0?
Hi All Does anyone know where I can get the Sybase drivers for ADO.NET for both versions, 1.1 and 2.0/3.0? Cheers Chris Burrell Hi Chris, There is no release of ASE ADO.NET Provider 2.0 (I assume you refer to ASE provider, not ASA - if ASA please port to sybase.public.sqlanywhere.general). For the 1.1 Provider: It is available in the ASE SDK for windows or the PC Client CDRom included with ASE product. On the SDK its available as 12.5.1 and 15.0 On ASE PC Client I think 12.5.1 is part of ASE 12.5.X and 15.0 is part of ASE 15.X 2.0 provider should release som...

Will AJAX Extensions 1.0 (for .NET 2.0) be affected by .NET 3.0?
Hello all,I have a web server that has a couple of site running using .NET 2.0 with the AJAX Extensions 1.0 (but not the ControlKit) and I need to install another Web App site that uses .NET 3.0. I need to know if installing .NET 3.0 will affect the sites that currently use 2.0 and the AJAX Extensions 1.0 as these sites are live and any down time would get me in the @~!£$.If there are issues, are there any work arounds? Many Thanks in advance  The .net Framework 3.0 and 3.5 add features to the .net framework 2.0 so installing the additional framework should not cause any pro...

Conversion of code from .net 1.1 to .net 2.0 posing a problem
Originally Posted by Akshay_Jadhav on the Microsoft Interoperability - Technical Interoperability Scenarios forumHI,I have converted .net 1.1 code to .net 2.0 using .net wizard. i have radiobutton whose checked property is set to false on page load, on clicking of a button on that page checked property of radiobutton is set to true and a dropdownlist is enabled. when i select some value in dropdownlist the page is posted back and checked property of radiobutton is again set to false(automatically) which is wrong, it should be true. Same code is working fine in .net 1.1,when i select som...

having .net 1.1 and .net 2.0
Was just wondering if you someone could tell me the ramifications of the following:  I have .net 2.0 but did not uninstally .net 1.1, i have visual studio 2003, and visual web developer installed on the computer as well as sql server 2000.  my question is whether that is a problem having the two runtimes installed at the same time?  i did this because i wanted to use VWD but keep vs 2003 in case i needed to do any development for work....any comments are appreciated.  --jpIf my post is helpful please mark as answerRegards -- jp(http://www.rzrsolutions.com/rzrWeb20/...

.net 2.0 to .net 1.1
Hello , This is shrirang. Currently i am working .net2.0 web application. but the same application is runing on production in .net 1.1 freamwork . we are not using any new feature of 2.0 in our application . can i run build of 2.0 on 1.1 freamwork . if yes can you  please tell me necessary steps to achive it .     Thanks in advance for your kind help     Regards Shrirang i think it is not possible to run the 2.0 application in 1.1 , so try to change to the frame work in the production server . ThanksRaja Ragothaman Hi Shrirang, Please contact web adm...

How to migrate from .NET V 1.0 to .NET v 2.0
  I have a asp.net applicatin currently running with v1.1.4322, I want to migrate to v2.0.50727 . I have run a "aspnet_regiss.exe -i". But it seems to be not enouft. When i open a page i get a "The 'system.serviceModel/serviceHostingEnvironment' configuration section cannot be created". And what about Visual Studio, I am using Visual Studio 2003. Does i have to change anything to make Visual Studio 2003 compile with version 2. And does i need to change somthing in machine.config ?  Best Regards   To get vs2003 to build the app for .NET 2.0, you need to upgrade to ...

Installing .Net Framework 1.0 Over .Net Framework 2.0
Hi all,My server has .Net Framework 2.0. Can I install .Net Framework 1.0 or I have to uninstall .Net 2.0, then install .net 1.0, then .net 2.0?Marking a Reply as 'Answered', not only GAIN us some POINTS, but it also HELP others to find RIGHT solution.  Hi,Hey no issues, u can directly install .Net 1.0 no matter you already have .Net 2.0 If this reply is answer to your question then mark this reply as Answer Get more solutions in SQL Server, C#.Net 3.5/2.0/1.1, SharePoint-Mohammad Nizamuddin What I know is if you install .Net Framework 2.0, the older version gets already i...

.NET 3.0 or .NET 2.0?
I'm going to move my exiting software to .net soon. I'm just wondering if I should wait for the .NET 3.0 framework to be released or if I can start with the 2.0 now? I'd say you can go ahead and move your code to .Net 2.0 as .Net 3.0 uses the CLR version 2.0.Basically, .net 3.0 is .net 2.0 PLUS some new features for presentation (GUI), communication and workflow process.  So the compiler as well as the language features used by the 2.0 runtime will be the same in 2.0 and 3.0"Never argue with an idiot; He will drag you down to his level and beat you with experienc...

.Net 1.1 and .Net 2.0 on the same webserver ?
Hi allCan you run .Net 1.1 and .Net 2.0 on the same webserver ? Does anybody do this currently and does both DNN 3.1.1 and the new dnn 4.0 work ok on this configuration ?/JohanFirstDev AB Affärssystem.net Yes, and Yes.John M. to elaborate a bit on that: yes, if you are using windows server 2003. You can select the .net version on a per application basis, however, you can only use one .net version per application pool. So just put your .net 2.0 applications in a different poolcheers,erikErik van Ballegoij, The Netherlands You can do it on XP Pro, or Windows 2000 Server also, you ...

Upgrading from .NET 1.1 to .NET 2.0
Hi,We write ASP.NET applications for a large UK organisation for which we have two servers - a dev server and a live intranet server.  I would like to convince management to upgrade the .NET framework from 1.1 to 2.0 (and incidently VS2003 to VS2005).If we install the new version of the dotnet framework, will there be any issues with our existing 1.1 applications?  If so, what will the issues likely to be?Your help is greatly appreciated.Ryan Penfold, Truro, UK. Two versions can coexist, so you shouldn't have any issues. So far we have not had any real issues with asp.net 1.1 a...

.net 2.0 v. .Net 1.1
Hi all:Im trying to figure out whether I should begin using 2.0 at this point.  Many people I spoke to have indicated that it may be too soon (for whatever reason-bugs, hosting availibility etc).  Can someone give the pros and cons at this point?  I just learned .net 1.1 and this would be the first time I've ever gone throught this sort of transition.  Also, what was frustrating about 1.1 is that some of the books that first came out had alot of problems with their code working.  Is there an authorotative book out yet with functioning examples?Any help would be ...

Web resources about - LDAP Authentication .Net 1.0 code to .Net 2.0 - asp.net.active-directory-ldap

Authentication - Wikipedia, the free encyclopedia
Authentication (from Greek : αὐθεντικός authentikos , "real, genuine," from αὐθέντης authentes , "author") is the act of confirming the truth ...

New Tools to Optimize App Authentication
At f8, we announced a redesigned Auth Dialog and a new authentication flow to give developers more control over people’s first experience with ...

Facebook Tells Some Developers They Have 48 Hours to Fix Authentication Data Leaks
... sent an email to what it calls a “very small percentage of the developer community” informing them their apps are suspected of leaking authentication ...

Lockdown - A better two-factor authentication experience on the App Store on iTunes
Get Lockdown - A better two-factor authentication experience on the App Store. See screenshots and ratings, and read customer reviews.


Sony Authentication Power Outlet Recognizes Users and Devices #DigInfo - YouTube
Sony Authentication Power Outlet Recognizes Users and Devices DigInfo TV - http://diginfo.tv 9/3/2012 NFC & Smart WORLD 2012 Sony Authentication ...

SafeNet brings Cloud-based authentication service to A/NZ
SafeNet has released its new Cloud-based authentication service, billed as Authentication-as-a-Service, in A/NZ.

Online account security: lazy authentication is still the norm
Even in the high-tech world of 2016, crims will be able to side-step your account security by making a phone call and saying they're you.

Digital authentication to become Google's next big focus
Streamlining the website login process a top priority, according to the company’s Australian business and consumer services manager Dan Metcalf. ...

ATO boosts service access via app and voice authentication
The ATO has announced it will extend its voice authentication system to its mobile app

Resources last updated: 1/17/2016 11:52:06 PM