Click here to Skip to main content
15,922,407 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
An ex-worker of our company left the following (VB?) code:
function AuthenticateUser(UserName, Password, Domain)
dim strUser
' assume failure
AuthenticateUser = false
strUser = UserName
strPassword = Password
strQuery = "SELECT cn FROM 'LDAP://" & Domain & "' WHERE objectClass='*' "
set oConn = server.CreateObject("ADODB.Connection")
oConn.Provider = "ADsDSOOBJECT"
oConn.Properties("User ID") = strUser
oConn.Properties("Password") = strPassword
oConn.Properties("Encrypt Password") = true "DS Query", strUser, strPassword
set cmd = server.CreateObject("ADODB.Command")
set cmd.ActiveConnection = oConn
cmd.CommandText = strQuery
on error resume next
set oRS = cmd.Execute
if oRS.bof or oRS.eof then
AuthenticateUser = false
AuthenticateUser = true
end if
set oRS = nothing
set oConn = nothing
end function

Due to upgrade functions, this code needs to be converted to C#.
Can anyone help me with that?
Updated 12-Aug-10 2:49am

Compile it as a DLL, then use Reflector to disassemble it into C#.

EDIT: Oh, this looks like VB6. In that case, the Reflector idea will not work. Look into System.Data.SqlClient.
Share this answer
Dimitri Backaert 11-Aug-10 16:39pm    
Hi aspdotnetdev,

thanks for the reply.
I don't have VB6.0 on my PC, so I can't really compile it.

VB.NET throws a lot of 'errors' on this function.

Any other way to do this?
AspDotNetDev 11-Aug-10 16:53pm    
See my update... I didn't realize at first that you were using VB6. The way to do this is to know VB6 and C# and convert manually. I already gave you a hint... you're code is executing an SQL command, so you'll need SqlClient. Specifically, you'll need SqlConnection and SqlCommand.
Here's a link that does what you want in VB.NET and C#. Scroll down to about a third of the way down the page and the C# code comes after the VB code. It's also well annotated so you can figure out what's going on.[^]

Good luck!
Share this answer
Or you can go online and convert it here[^]
Share this answer
this is very easy to convert the above code in to c#

let's start
<pre> void AuntenticateUser(string username,string password,string Domain)
string struser="";
string password= password;
string query ="SELECT cn FROM 'LDAP://" + Domain + "' WHERE objectClass='*' ";
//if your database details is managed in web.config file input that connection string here or
// provide the database connection here on the below code inside the "this area"
System.Data.SqlClient.SqlConnection con = "";
//oConn.Provider = "ADsDSOOBJECT" this line is not required as we already have given connection string and
System.Data.SqlClient.SqlCommand cmd;
cmd = new System.Data.SqlClient.SqlCommand("",con);
cmd.Parameters.Add("User ID",SqlDbType.VarChar).Value = struser;

cmd.Parameters.Add("Encrypt Password",SqlDbType.Bit).Value=true;
System.Data.SqlClient.SqlDataReader dr = cmd.ExecuteNonQuery();

AuntenticateUser = true;


please post your comments to [Email address removed]
Share this answer
Goutam Patra 13-Aug-10 2:39am    
Never post your email address to aviod spam

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900