473,480 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Another block of C# code to convert

Ty
Here is another block that I can not get to convert. This is a class
module.

public bool IsAuthenticated(string domain, string username, string
pwd)
{
string domainAndUsername = domain + @"\" + username;
DirectoryEntry entry = new DirectoryEntry( _path,
domainAndUsername, pwd);
try
{
// Bind to the native AdsObject to force authentication.
Object obj = entry.NativeObject;
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + username + ")";
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();
if(null == result)
{
return false;
}
// Update the new path to the user in the directory
_path = result.Path;
_filterAttribute = (String)result.Properties["cn"][0];
}
catch (Exception ex)
{
throw new Exception("Error authenticating user. " + ex.Message);
}
return true;
}

}

Any help would be apperciated.
Jun 27 '08 #1
6 1475

"Ty" <tb*****@lewistownhospital.orgwrote in message
news:8b**********************************@59g2000h sb.googlegroups.com...
Here is another block that I can not get to convert. This is a class
module.

public bool IsAuthenticated(string domain, string username, string
pwd)
{
string domainAndUsername = domain + @"\" + username;
DirectoryEntry entry = new DirectoryEntry( _path,
domainAndUsername, pwd);
try
{
// Bind to the native AdsObject to force authentication.
Object obj = entry.NativeObject;
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + username + ")";
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();
if(null == result)
{
return false;
}
// Update the new path to the user in the directory
_path = result.Path;
_filterAttribute = (String)result.Properties["cn"][0];
}
catch (Exception ex)
{
throw new Exception("Error authenticating user. " + ex.Message);
}
return true;
}

}

Any help would be apperciated.

Public Function IsAuthenticated(ByVal domain As String, ByVal username As
String, ByVal pwd As String) As Boolean
Dim domainAndUsername As String = domain + "\" + username
Dim entry As New DirectoryEntry(_path, domainAndUsername, pwd)
Try
' Bind to the native AdsObject to force authentication.
Dim obj As Object = entry.NativeObject
Dim search As New DirectorySearcher(entry)
search.Filter = "(SAMAccountName=" + username + ")"
search.PropertiesToLoad.Add("cn")
Dim result As SearchResult = search.FindOne()
If result Is Nothing Then
Return False
End If
' Update the new path to the user in the directory
_path = result.Path
_filterAttribute = DirectCast(result.Properties("cn")(0), String)
Catch ex As Exception
Throw New Exception("Error authenticating user. " + ex.Message)
End Try
Return True
End Function
http://codeconverter.sharpdevelop.ne...Converter.aspx

LS

Jun 27 '08 #2
Hi Seth,

Just for fun.

I saw your code and made this from it, looks for me more as VB 2008

I hope Anton will show what it does with his converter, I expect that it is
better than you showed with those plusses.

\\\
Option Infer On
Option Strict On
Option Explicit On
Imports System.DirectoryServices

Module Module1
Sub Main()
End Sub
Public Function IsAuthenticated(ByVal domain As String, ByVal username
As String, ByVal pwd As String) As Boolean
Dim path, filterAttribute As String 'dummies
Dim domainAndUsername = domain & "\" & username
Dim entry As New DirectoryEntry(path, domainAndUsername, pwd)
Try
' Bind to the native AdsObject to force authentication.
Dim obj = entry.NativeObject
Dim search As New DirectorySearcher(entry)
search.Filter = "(SAMAccountName=" & username & ")"
search.PropertiesToLoad.Add("cn")
Dim result = search.FindOne()
If result IsNot Nothing Then
'Update the new path to the user in the directory
path = result.Path
filterAttribute = result.Properties("cn")(0).ToString
Return True
Else
Return False
End If
Catch ex As Exception
Throw New Exception("Error authenticating user. " & ex.Message)
End Try
End Function
End Module
///
(I did not test the result, only changed the code)

Cor

"Lloyd Sheen" <a@b.cschreef in bericht
news:%2****************@TK2MSFTNGP03.phx.gbl...
>
"Ty" <tb*****@lewistownhospital.orgwrote in message
news:8b**********************************@59g2000h sb.googlegroups.com...
>Here is another block that I can not get to convert. This is a class
module.

public bool IsAuthenticated(string domain, string username, string
pwd)
{
string domainAndUsername = domain + @"\" + username;
DirectoryEntry entry = new DirectoryEntry( _path,
domainAndUsername, pwd);
try
{
// Bind to the native AdsObject to force authentication.
Object obj = entry.NativeObject;
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + username + ")";
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();
if(null == result)
{
return false;
}
// Update the new path to the user in the directory
_path = result.Path;
_filterAttribute = (String)result.Properties["cn"][0];
}
catch (Exception ex)
{
throw new Exception("Error authenticating user. " + ex.Message);
}
return true;
}

}

Any help would be apperciated.


Public Function IsAuthenticated(ByVal domain As String, ByVal username As
String, ByVal pwd As String) As Boolean
Dim domainAndUsername As String = domain + "\" + username
Dim entry As New DirectoryEntry(_path, domainAndUsername, pwd)
Try
' Bind to the native AdsObject to force authentication.
Dim obj As Object = entry.NativeObject
Dim search As New DirectorySearcher(entry)
search.Filter = "(SAMAccountName=" + username + ")"
search.PropertiesToLoad.Add("cn")
Dim result As SearchResult = search.FindOne()
If result Is Nothing Then
Return False
End If
' Update the new path to the user in the directory
_path = result.Path
_filterAttribute = DirectCast(result.Properties("cn")(0), String)
Catch ex As Exception
Throw New Exception("Error authenticating user. " + ex.Message)
End Try
Return True
End Function
http://codeconverter.sharpdevelop.ne...Converter.aspx

LS
Jun 27 '08 #3
Except for using '&' instead of '+' (which may be ambiguous in some cases),
our conversion was quite similar. One difference is that 'DirectCast' is not
the general purpose equivalent for the C# casting operator - CType is a more
reliable replacement (google on DirectCast to see why).
--
http://www.tangiblesoftwaresolutions.com
C++ to C#
C++ to VB
C++ to Java
VB to Java
Java to VB & C#
Instant C#: VB to C#
Instant VB: C# to VB
Instant C++: VB, C#, or Java to C++/CLI
"Cor Ligthert[MVP]" wrote:
Hi Seth,

Just for fun.

I saw your code and made this from it, looks for me more as VB 2008

I hope Anton will show what it does with his converter, I expect that it is
better than you showed with those plusses.

\\\
Option Infer On
Option Strict On
Option Explicit On
Imports System.DirectoryServices

Module Module1
Sub Main()
End Sub
Public Function IsAuthenticated(ByVal domain As String, ByVal username
As String, ByVal pwd As String) As Boolean
Dim path, filterAttribute As String 'dummies
Dim domainAndUsername = domain & "\" & username
Dim entry As New DirectoryEntry(path, domainAndUsername, pwd)
Try
' Bind to the native AdsObject to force authentication.
Dim obj = entry.NativeObject
Dim search As New DirectorySearcher(entry)
search.Filter = "(SAMAccountName=" & username & ")"
search.PropertiesToLoad.Add("cn")
Dim result = search.FindOne()
If result IsNot Nothing Then
'Update the new path to the user in the directory
path = result.Path
filterAttribute = result.Properties("cn")(0).ToString
Return True
Else
Return False
End If
Catch ex As Exception
Throw New Exception("Error authenticating user. " & ex.Message)
End Try
End Function
End Module
///
(I did not test the result, only changed the code)

Cor

"Lloyd Sheen" <a@b.cschreef in bericht
news:%2****************@TK2MSFTNGP03.phx.gbl...

"Ty" <tb*****@lewistownhospital.orgwrote in message
news:8b**********************************@59g2000h sb.googlegroups.com...
Here is another block that I can not get to convert. This is a class
module.

public bool IsAuthenticated(string domain, string username, string
pwd)
{
string domainAndUsername = domain + @"\" + username;
DirectoryEntry entry = new DirectoryEntry( _path,
domainAndUsername, pwd);
try
{
// Bind to the native AdsObject to force authentication.
Object obj = entry.NativeObject;
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + username + ")";
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();
if(null == result)
{
return false;
}
// Update the new path to the user in the directory
_path = result.Path;
_filterAttribute = (String)result.Properties["cn"][0];
}
catch (Exception ex)
{
throw new Exception("Error authenticating user. " + ex.Message);
}
return true;
}

}

Any help would be apperciated.

Public Function IsAuthenticated(ByVal domain As String, ByVal username As
String, ByVal pwd As String) As Boolean
Dim domainAndUsername As String = domain + "\" + username
Dim entry As New DirectoryEntry(_path, domainAndUsername, pwd)
Try
' Bind to the native AdsObject to force authentication.
Dim obj As Object = entry.NativeObject
Dim search As New DirectorySearcher(entry)
search.Filter = "(SAMAccountName=" + username + ")"
search.PropertiesToLoad.Add("cn")
Dim result As SearchResult = search.FindOne()
If result Is Nothing Then
Return False
End If
' Update the new path to the user in the directory
_path = result.Path
_filterAttribute = DirectCast(result.Properties("cn")(0), String)
Catch ex As Exception
Throw New Exception("Error authenticating user. " + ex.Message)
End Try
Return True
End Function
http://codeconverter.sharpdevelop.ne...Converter.aspx

LS
Jun 27 '08 #4
David,

That was the most important for me,
Except for using '&' instead of '+' (which may be ambiguous in some
cases),
our conversion was quite similar.
I made the code particulary for 2008 you should not expect that from a
converter

The guy who did the casting in C# with (string)bla did of course as well not
so a good documentative job, as a ToString() from object is one of the most
basic elements of dotnet.

Cor

"David Anton" <Da********@discussions.microsoft.comschreef in bericht
news:C2**********************************@microsof t.com...
Except for using '&' instead of '+' (which may be ambiguous in some
cases),
our conversion was quite similar. One difference is that 'DirectCast' is
not
the general purpose equivalent for the C# casting operator - CType is a
more
reliable replacement (google on DirectCast to see why).
--
http://www.tangiblesoftwaresolutions.com
C++ to C#
C++ to VB
C++ to Java
VB to Java
Java to VB & C#
Instant C#: VB to C#
Instant VB: C# to VB
Instant C++: VB, C#, or Java to C++/CLI
"Cor Ligthert[MVP]" wrote:
>Hi Seth,

Just for fun.

I saw your code and made this from it, looks for me more as VB 2008

I hope Anton will show what it does with his converter, I expect that it
is
better than you showed with those plusses.

\\\
Option Infer On
Option Strict On
Option Explicit On
Imports System.DirectoryServices

Module Module1
Sub Main()
End Sub
Public Function IsAuthenticated(ByVal domain As String, ByVal
username
As String, ByVal pwd As String) As Boolean
Dim path, filterAttribute As String 'dummies
Dim domainAndUsername = domain & "\" & username
Dim entry As New DirectoryEntry(path, domainAndUsername, pwd)
Try
' Bind to the native AdsObject to force authentication.
Dim obj = entry.NativeObject
Dim search As New DirectorySearcher(entry)
search.Filter = "(SAMAccountName=" & username & ")"
search.PropertiesToLoad.Add("cn")
Dim result = search.FindOne()
If result IsNot Nothing Then
'Update the new path to the user in the directory
path = result.Path
filterAttribute = result.Properties("cn")(0).ToString
Return True
Else
Return False
End If
Catch ex As Exception
Throw New Exception("Error authenticating user. " &
ex.Message)
End Try
End Function
End Module
///
(I did not test the result, only changed the code)

Cor

"Lloyd Sheen" <a@b.cschreef in bericht
news:%2****************@TK2MSFTNGP03.phx.gbl...
>
"Ty" <tb*****@lewistownhospital.orgwrote in message
news:8b**********************************@59g2000h sb.googlegroups.com...
Here is another block that I can not get to convert. This is a class
module.

public bool IsAuthenticated(string domain, string username, string
pwd)
{
string domainAndUsername = domain + @"\" + username;
DirectoryEntry entry = new DirectoryEntry( _path,
domainAndUsername, pwd);
try
{
// Bind to the native AdsObject to force authentication.
Object obj = entry.NativeObject;
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + username + ")";
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();
if(null == result)
{
return false;
}
// Update the new path to the user in the directory
_path = result.Path;
_filterAttribute = (String)result.Properties["cn"][0];
}
catch (Exception ex)
{
throw new Exception("Error authenticating user. " + ex.Message);
}
return true;
}

}

Any help would be apperciated.
Public Function IsAuthenticated(ByVal domain As String, ByVal username
As
String, ByVal pwd As String) As Boolean
Dim domainAndUsername As String = domain + "\" + username
Dim entry As New DirectoryEntry(_path, domainAndUsername, pwd)
Try
' Bind to the native AdsObject to force authentication.
Dim obj As Object = entry.NativeObject
Dim search As New DirectorySearcher(entry)
search.Filter = "(SAMAccountName=" + username + ")"
search.PropertiesToLoad.Add("cn")
Dim result As SearchResult = search.FindOne()
If result Is Nothing Then
Return False
End If
' Update the new path to the user in the directory
_path = result.Path
_filterAttribute = DirectCast(result.Properties("cn")(0), String)
Catch ex As Exception
Throw New Exception("Error authenticating user. " + ex.Message)
End Try
Return True
End Function
http://codeconverter.sharpdevelop.ne...Converter.aspx

LS
Jun 27 '08 #5
Ty schreef:
Here is another block that I can not get to convert. This is a class
module.

public bool IsAuthenticated(string domain, string username, string
pwd)
{
string domainAndUsername = domain + @"\" + username;
DirectoryEntry entry = new DirectoryEntry( _path,
domainAndUsername, pwd);
try
{
// Bind to the native AdsObject to force authentication.
Object obj = entry.NativeObject;
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + username + ")";
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();
if(null == result)
{
return false;
}
// Update the new path to the user in the directory
_path = result.Path;
_filterAttribute = (String)result.Properties["cn"][0];
}
catch (Exception ex)
{
throw new Exception("Error authenticating user. " + ex.Message);
}
return true;
}

}

Any help would be apperciated.

You mean you posted a part of a class module without telling wich
references were set and without providing the class scoped variabels

The next time provide this information , maybe this is the reasson why
nobody bothered until so far cause the code is pretty simple .
first of all set a refernce to system.DirectoryServices

then in the top of the code file you put this import statement

Imports System.DirectoryServices
Private _path As String
Private _filterAttribute As String
Public Function IsAuthenticated(ByVal domain As String, ByVal
username As String, ByVal pwd As String) As Boolean
Dim domainAndUsername As String = domain + "\" + username
Dim entry As New DirectoryEntry(_path, domainAndUsername, pwd)
Try
' Bind to the native AdsObject to force authentication.
Dim obj As Object = entry.NativeObject
Dim search As New DirectorySearcher(entry)
search.Filter = "(SAMAccountName=" + username + ")"
search.PropertiesToLoad.Add("cn")
Dim result As SearchResult = search.FindOne()
If result Is Nothing Then
Return False
End If
' Update the new path to the user in the directory
_path = result.Path
_filterAttribute =
DirectCast(result.Properties("cn")(0),String)
Catch ex As Exception
Throw New Exception("Error authenticating user. " + ex.Message)
End Try
Return True
End Function

regards
Michel Posseth [MCP]

Jun 29 '08 #6
Michel Posseth schreef:
Ty schreef:
>Here is another block that I can not get to convert. This is a class
module.

public bool IsAuthenticated(string domain, string username, string
pwd)
{
string domainAndUsername = domain + @"\" + username;
DirectoryEntry entry = new DirectoryEntry( _path,
domainAndUsername, pwd);
try
{
// Bind to the native AdsObject to force authentication.
Object obj = entry.NativeObject;
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + username + ")";
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();
if(null == result)
{
return false;
}
// Update the new path to the user in the directory
_path = result.Path;
_filterAttribute = (String)result.Properties["cn"][0];
}
catch (Exception ex)
{
throw new Exception("Error authenticating user. " + ex.Message);
}
return true;
}

}

Any help would be apperciated.


You mean you posted a part of a class module without telling wich
references were set and without providing the class scoped variabels

The next time provide this information , maybe this is the reasson why
nobody bothered until so far cause the code is pretty simple .
first of all set a refernce to system.DirectoryServices

then in the top of the code file you put this import statement

Imports System.DirectoryServices
Private _path As String
Private _filterAttribute As String
Public Function IsAuthenticated(ByVal domain As String, ByVal
username As String, ByVal pwd As String) As Boolean
Dim domainAndUsername As String = domain + "\" + username
Dim entry As New DirectoryEntry(_path, domainAndUsername, pwd)
Try
' Bind to the native AdsObject to force authentication.
Dim obj As Object = entry.NativeObject
Dim search As New DirectorySearcher(entry)
search.Filter = "(SAMAccountName=" + username + ")"
search.PropertiesToLoad.Add("cn")
Dim result As SearchResult = search.FindOne()
If result Is Nothing Then
Return False
End If
' Update the new path to the user in the directory
_path = result.Path
_filterAttribute =
DirectCast(result.Properties("cn")(0),String)
Catch ex As Exception
Throw New Exception("Error authenticating user. " + ex.Message)
End Try
Return True
End Function

regards
Michel Posseth [MCP]
hmmm on this computer i installed Thunderbird ( just for testing :-) )
but it looks like i am a bit behind reality ( thought no one had
answered this one yet )

Jun 29 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4405
by: Francesco Moi | last post by:
Hi. I've got this piece of code: ----------------//--------------------- <html><head> <style type="text/css"> #block {margin:0 0 0 0; display:block;} ..left-pic {display:block; float:left;}...
1
1846
by: Andy | last post by:
Hi All, I'm basically just trying to get started with the Exception Management Application Block and am having some technical difficulties. All I want to do to begin with is create a simple...
188
7033
by: christopher diggins | last post by:
I have posted a C# critique at http://www.heron-language.com/c-sharp-critique.html. To summarize I bring up the following issues : - unsafe code - attributes - garbage collection -...
2
1413
by: Alex | last post by:
Hi. What would happen if an exception occurs inside a Finally block and at the same time inside the try another exception was thrown without been handled by any catch? Alejandro.
4
1141
by: John Dann | last post by:
I seem to be transitioning from VB6 to VB.Net very unevenly - got some fancier things working OK but then trip over something that ought to be simple in .Net: It's the change in WinForm...
0
1780
by: Robert | last post by:
After failing on a yield/iterator-continuation problem in Python (see below) I tried the Ruby (1.8.2) language first time on that construct: The example tries to convert a block callback interface...
1
1587
by: ArizonaState | last post by:
I am trying to block certain dates in the calendar to be Selectable. I have been able to do this for weekends .. CODE If e.Day.IsWeekend Then e.Day.IsSelectable = False /CODE But I...
0
377
by: David C | last post by:
I am getting this error in the Databound event of a GridView and I am having a difficult time debugging. I do not get the error on every record that I edit in the GridView. The error is occurring...
11
3916
by: michelqa | last post by:
Hello, I can retrieve column text from a ListView in another process but I cant figure out how to access to structure elements (LVCOLUMN) <code> //Handle variable is a valid ListView handle ...
0
7033
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7027
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7071
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6726
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5318
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4468
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2974
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1291
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
557
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.