I'm creating a hashtable of a list of users in AD. The keys are UserID and
Password. I want to loop through the table to compare the userID and password
with values that a user has entered. Ideally I'd want to run through the
records until I find one that matches with the entered UserID and then
compare passwords.
I've googled and I can't really find any examples of how to do this.
Anyone got any ideas? Thanks in advance!
JuliaTry :
http://msdn2.microsoft.com/en-us/li...le_members.aspx
In particular Contains(key) and Item(Key) ? Else please elaborate about the
specific problem you are running into...
(Looks unclear but you seems to imply that you could have multiple users
with the same id but with different passwords ? Are you sure this can happen
?!)
--
Patrice
"Julia B" <JuliaB@dotnet.itags.org.discussions.microsoft.coma crit dans le message de
news: 1C24D0ED-5ED8-4420-892A-6AD54520E592@dotnet.itags.org.microsoft.com...
Quote:
Originally Posted by
Hi all
>
I'm creating a hashtable of a list of users in AD. The keys are UserID and
Password. I want to loop through the table to compare the userID and
password
with values that a user has entered. Ideally I'd want to run through the
records until I find one that matches with the entered UserID and then
compare passwords.
>
I've googled and I can't really find any examples of how to do this.
>
Anyone got any ideas? Thanks in advance!
>
Julia
"Julia B" <JuliaB@dotnet.itags.org.discussions.microsoft.comwrote in message
news:1C24D0ED-5ED8-4420-892A-6AD54520E592@dotnet.itags.org.microsoft.com...
Quote:
Originally Posted by
I'm creating a hashtable of a list of users in AD. The keys are UserID and
Password. I want to loop through the table to compare the userID and
password
with values that a user has entered. Ideally I'd want to run through the
records until I find one that matches with the entered UserID and then
compare passwords.
>
I've googled and I can't really find any examples of how to do this.
>
Anyone got any ideas? Thanks in advance!
Slightly puzzled...
Although user passwords are stored in ActiveDirectory, you certainly can't
retrieve them in the same way as e.g. you can retrieve a user's email
address etc...
Where are you getting UserID and Password from to populate your
Hashtable...?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
Sorry, let me be more specific. No there wouldn't be more than one user with
the same id. I'm just trying to find a user based on user entered text. My
problem is that I can't seem to work out how to go through the hashtable
"rows". Hashtable doesn't have a row property so how do you loop through? Or
do you loop through keys? If so, what are they declared as? i.e.
dim key as ??
for each key in hashtable
if key = "userid" then
if value = "xxxx" then
end if
end if
next
The problem is that, although I am able to declare a variable as a
hashtable, hashtables appear to have no members/properties/functions
associated with them on my intellisense. Code is below.
Hope that makes a bit more sense.
Julia
Public Function ValidateIDPassword(ByVal enteredNetworkID As String, ByVal
enteredPassword As String) As Boolean
Dim usersTable As Hashtable = GetAllUsers("ukntdc01.rcuk.com:389")
'now loop through the usersTable and check if there's a matching user
'this is where I have no idea what to do
End Function
Public Function GetAllUsers(ByVal ldapServerName As String) As Hashtable
'this function returns all the ldap ad users for searching in the
validated id
Dim oRoot As DirectoryServices.DirectoryEntry = New
DirectoryServices.DirectoryEntry _
("LDAP://" & ldapServerName &
"/OU=EVOII,DC=rcuknet,DC=rockwellcollins,DC=com")
Dim oSearcher As DirectoryServices.DirectorySearcher = New
DirectoryServices.DirectorySearcher(oRoot)
Dim oResults As DirectoryServices.SearchResultCollection
Dim oResult As DirectoryServices.SearchResult
Dim RetArray As Hashtable
oSearcher.PropertiesToLoad.Add("SAMAccountName")
oSearcher.PropertiesToLoad.Add("userPassword")
oResults = oSearcher.FindAll
For Each oResult In oResults
If Not
oResult.GetDirectoryEntry().Properties("SAMAccountName").Value = "" Then
RetArray.Add("UserID",
oResult.GetDirectoryEntry().Properties("SAMAccountName").Value)
RetArray.Add("Password",
oResult.GetDirectoryEntry().Properties("userPassword").Value)
End If
Next
Return RetArray
End Function
"Patrice" wrote:
Quote:
Originally Posted by
Try :
http://msdn2.microsoft.com/en-us/li...le_members.aspx
>
In particular Contains(key) and Item(Key) ? Else please elaborate about the
specific problem you are running into...
>
(Looks unclear but you seems to imply that you could have multiple users
with the same id but with different passwords ? Are you sure this can happen
?!)
>
--
Patrice
>
"Julia B" <JuliaB@dotnet.itags.org.discussions.microsoft.coma écrit dans le message de
news: 1C24D0ED-5ED8-4420-892A-6AD54520E592@dotnet.itags.org.microsoft.com...
Quote:
Originally Posted by
Hi all
I'm creating a hashtable of a list of users in AD. The keys are UserID and
Password. I want to loop through the table to compare the userID and
password
with values that a user has entered. Ideally I'd want to run through the
records until I find one that matches with the entered UserID and then
compare passwords.
I've googled and I can't really find any examples of how to do this.
Anyone got any ideas? Thanks in advance!
Julia
>
>
>
Thanks Mark, well that's interesting. I got some code from a website and I
made an assumption that password was just another property you could
retrieve. I haven't tested any of my code out yet, so perhaps I won't even
get as far as the hashtable!!
I have an intranet application with a sign on page that has networkID and
password text entry boxes. I want to compare the entries in the text boxes to
ensure that (a) there is a matching user id and (b) the user has entered the
correct password.
Should I rethink my approach and, if so, how?
My (obviously incorrect) code is:
Public Function GetAllUsers(ByVal ldapServerName As String, ByVal networkID
As String) As Hashtable
'this function returns all the ldap ad users for searching in the
validated id
Dim oRoot As DirectoryServices.DirectoryEntry = New
DirectoryServices.DirectoryEntry _
("LDAP://" & ldapServerName &
"/OU=EVOII,DC=rcuknet,DC=rockwellcollins,DC=com")
Dim oSearcher As DirectoryServices.DirectorySearcher = New
DirectoryServices.DirectorySearcher(oRoot)
Dim oResults As DirectoryServices.SearchResultCollection
Dim oResult As DirectoryServices.SearchResult
Dim RetArray As Hashtable
oSearcher.PropertiesToLoad.Add("SAMAccountName")
oSearcher.PropertiesToLoad.Add("userPassword")
oResults = oSearcher.FindAll
For Each oResult In oResults
If Not
oResult.GetDirectoryEntry().Properties("SAMAccountName").Value = "" Then
RetArray.Add("UserID",
oResult.GetDirectoryEntry().Properties("SAMAccountName").Value)
RetArray.Add("Password",
oResult.GetDirectoryEntry().Properties("userPassword").Value)
End If
Next
Return RetArray
End Function
Julia
"Mark Rae [MVP]" wrote:
Quote:
Originally Posted by
"Julia B" <JuliaB@dotnet.itags.org.discussions.microsoft.comwrote in message
news:1C24D0ED-5ED8-4420-892A-6AD54520E592@dotnet.itags.org.microsoft.com...
>
Quote:
Originally Posted by
I'm creating a hashtable of a list of users in AD. The keys are UserID and
Password. I want to loop through the table to compare the userID and
password
with values that a user has entered. Ideally I'd want to run through the
records until I find one that matches with the entered UserID and then
compare passwords.
I've googled and I can't really find any examples of how to do this.
Anyone got any ideas? Thanks in advance!
>
Slightly puzzled...
>
Although user passwords are stored in ActiveDirectory, you certainly can't
retrieve them in the same way as e.g. you can retrieve a user's email
address etc...
>
Where are you getting UserID and Password from to populate your
Hashtable...?
>
>
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
>
>
You don't have to loop. Try :
Dim h As New System.Collections.Hashtable
h.Add("A", "PasswordA")
h.Add("B", "PasswordB")
MsgBox(h("A"))
MsgBox(h.Contains("A"))
MsgBox(h.Contains("Z"))
You should see :
- PasswordA (value retrieved from the collection for the "A" key)
- True (the "A" key is part of the collection)
- False (the "Z" key is not part of the collection)
--
Patrice
"Julia B" <JuliaB@dotnet.itags.org.discussions.microsoft.coma crit dans le message de
news: 12A03103-2B4D-4BF3-BFEE-B696C968B339@dotnet.itags.org.microsoft.com...
Quote:
Originally Posted by
Sorry, let me be more specific. No there wouldn't be more than one user
with
the same id. I'm just trying to find a user based on user entered text. My
problem is that I can't seem to work out how to go through the hashtable
"rows". Hashtable doesn't have a row property so how do you loop through?
Or
do you loop through keys? If so, what are they declared as? i.e.
>
dim key as ??
for each key in hashtable
if key = "userid" then
if value = "xxxx" then
end if
end if
next
>
The problem is that, although I am able to declare a variable as a
hashtable, hashtables appear to have no members/properties/functions
associated with them on my intellisense. Code is below.
>
Hope that makes a bit more sense.
>
Julia
>
Public Function ValidateIDPassword(ByVal enteredNetworkID As String, ByVal
enteredPassword As String) As Boolean
Dim usersTable As Hashtable = GetAllUsers("ukntdc01.rcuk.com:389")
'now loop through the usersTable and check if there's a matching
user
'this is where I have no idea what to do
>
End Function
>
Public Function GetAllUsers(ByVal ldapServerName As String) As
Hashtable
'this function returns all the ldap ad users for searching in the
validated id
Dim oRoot As DirectoryServices.DirectoryEntry = New
DirectoryServices.DirectoryEntry _
("LDAP://" & ldapServerName &
"/OU=EVOII,DC=rcuknet,DC=rockwellcollins,DC=com")
Dim oSearcher As DirectoryServices.DirectorySearcher = New
DirectoryServices.DirectorySearcher(oRoot)
Dim oResults As DirectoryServices.SearchResultCollection
Dim oResult As DirectoryServices.SearchResult
Dim RetArray As Hashtable
>
oSearcher.PropertiesToLoad.Add("SAMAccountName")
oSearcher.PropertiesToLoad.Add("userPassword")
oResults = oSearcher.FindAll
>
For Each oResult In oResults
>
If Not
oResult.GetDirectoryEntry().Properties("SAMAccountName").Value = "" Then
RetArray.Add("UserID",
oResult.GetDirectoryEntry().Properties("SAMAccountName").Value)
RetArray.Add("Password",
oResult.GetDirectoryEntry().Properties("userPassword").Value)
End If
>
Next
>
Return RetArray
>
End Function
>
"Patrice" wrote:
>
Quote:
Originally Posted by
>Try :
>http://msdn2.microsoft.com/en-us/li...le_members.aspx
>>
>In particular Contains(key) and Item(Key) ? Else please elaborate about
>the
>specific problem you are running into...
>>
>(Looks unclear but you seems to imply that you could have multiple users
>with the same id but with different passwords ? Are you sure this can
>happen
>?!)
>>
>--
>Patrice
>>
>"Julia B" <JuliaB@dotnet.itags.org.discussions.microsoft.coma crit dans le message de
>news: 1C24D0ED-5ED8-4420-892A-6AD54520E592@dotnet.itags.org.microsoft.com...
Quote:
Originally Posted by
Hi all
>
I'm creating a hashtable of a list of users in AD. The keys are UserID
and
Password. I want to loop through the table to compare the userID and
password
with values that a user has entered. Ideally I'd want to run through
the
records until I find one that matches with the entered UserID and then
compare passwords.
>
I've googled and I can't really find any examples of how to do this.
>
Anyone got any ideas? Thanks in advance!
>
Julia
>>
>>
>>
"Julia B" <JuliaB@dotnet.itags.org.discussions.microsoft.comwrote in message
news:C8AD8989-0F18-4D42-BA64-D2BD79F22C85@dotnet.itags.org.microsoft.com...
Quote:
Originally Posted by
Thanks Mark, well that's interesting. I got some code from a website and I
made an assumption that password was just another property you could
retrieve. I haven't tested any of my code out yet, so perhaps I won't even
get as far as the hashtable!!
User passwords are stored in a hashed state and can't be retrieved directly,
for fairly obvious security reasons!
http://www.velocityreviews.com/foru...-directory.html
Quote:
Originally Posted by
I have an intranet application with a sign on page that has networkID and
password text entry boxes. I want to compare the entries in the text boxes
to
ensure that (a) there is a matching user id and (b) the user has entered
the
correct password.
Ah, well that's a breeze!
Quote:
Originally Posted by
Should I rethink my approach and, if so, how?
Yup, as below. This code is in C# (I never go anywhere near VB.NET...), but
it should be fairly easy to convert:
using System;
using System.Collections.Generic;
using System.DirectoryServices;
using System.DirectoryServices.Protocols;
using System.Net;
bool Logon(string pstrUser, string pstrPassword)
{
try
{
string strDomain = System.Environment.UserDomainName; // modify
as required
using (LdapConnection objLDAP = new LdapConnection(strDomain))
{
objLDAP.AuthType = AuthType.Kerberos;
objLDAP.Bind(new NetworkCredential(pstrUser, pstrPassword,
strDomain));
return true;
}
}
catch (System.Runtime.InteropServices.COMException)
{
return false;
}
catch (Exception)
{
return false;
}
}
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
Hi Mark
Thanks very much for this. It's much appreciated. I'll give this a go and
let you know if I come across any problems.
Julia
"Mark Rae [MVP]" wrote:
Quote:
Originally Posted by
"Julia B" <JuliaB@dotnet.itags.org.discussions.microsoft.comwrote in message
news:C8AD8989-0F18-4D42-BA64-D2BD79F22C85@dotnet.itags.org.microsoft.com...
>
Quote:
Originally Posted by
Thanks Mark, well that's interesting. I got some code from a website and I
made an assumption that password was just another property you could
retrieve. I haven't tested any of my code out yet, so perhaps I won't even
get as far as the hashtable!!
>
User passwords are stored in a hashed state and can't be retrieved directly,
for fairly obvious security reasons!
http://www.velocityreviews.com/foru...-directory.html
>
Quote:
Originally Posted by
I have an intranet application with a sign on page that has networkID and
password text entry boxes. I want to compare the entries in the text boxes
to
ensure that (a) there is a matching user id and (b) the user has entered
the
correct password.
>
Ah, well that's a breeze!
>
Quote:
Originally Posted by
Should I rethink my approach and, if so, how?
>
Yup, as below. This code is in C# (I never go anywhere near VB.NET...), but
it should be fairly easy to convert:
>
using System;
using System.Collections.Generic;
using System.DirectoryServices;
using System.DirectoryServices.Protocols;
using System.Net;
>
bool Logon(string pstrUser, string pstrPassword)
{
try
{
string strDomain = System.Environment.UserDomainName; // modify
as required
using (LdapConnection objLDAP = new LdapConnection(strDomain))
{
objLDAP.AuthType = AuthType.Kerberos;
objLDAP.Bind(new NetworkCredential(pstrUser, pstrPassword,
strDomain));
return true;
}
}
catch (System.Runtime.InteropServices.COMException)
{
return false;
}
catch (Exception)
{
return false;
}
}
>
>
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
>
>
"Julia B" <JuliaB@dotnet.itags.org.discussions.microsoft.comwrote in message
news:6694EE88-EB74-45A5-9EFE-6E804E3D97A5@dotnet.itags.org.microsoft.com...
Quote:
Originally Posted by
Thanks very much for this. It's much appreciated. I'll give this a go and
let you know if I come across any problems.
No problem.
And back to the original question, you should seriously consider using
generics rather than hashtables and arrays etc...
Won't help you in this particular case, though, but they're well worth
investigating for the future...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
Mark,
I've hit a problem. I should have explained that I'm using .net 1.1. It
would seem that System.Collections.Generic and
System.DirectoryServices.Protocols are not available to me. I'm getting some
errors after converting the code (ldapconnection object and authtype).
Julia
"Mark Rae [MVP]" wrote:
Quote:
Originally Posted by
"Julia B" <JuliaB@dotnet.itags.org.discussions.microsoft.comwrote in message
news:C8AD8989-0F18-4D42-BA64-D2BD79F22C85@dotnet.itags.org.microsoft.com...
>
Quote:
Originally Posted by
Thanks Mark, well that's interesting. I got some code from a website and I
made an assumption that password was just another property you could
retrieve. I haven't tested any of my code out yet, so perhaps I won't even
get as far as the hashtable!!
>
User passwords are stored in a hashed state and can't be retrieved directly,
for fairly obvious security reasons!
http://www.velocityreviews.com/foru...-directory.html
>
Quote:
Originally Posted by
I have an intranet application with a sign on page that has networkID and
password text entry boxes. I want to compare the entries in the text boxes
to
ensure that (a) there is a matching user id and (b) the user has entered
the
correct password.
>
Ah, well that's a breeze!
>
Quote:
Originally Posted by
Should I rethink my approach and, if so, how?
>
Yup, as below. This code is in C# (I never go anywhere near VB.NET...), but
it should be fairly easy to convert:
>
using System;
using System.Collections.Generic;
using System.DirectoryServices;
using System.DirectoryServices.Protocols;
using System.Net;
>
bool Logon(string pstrUser, string pstrPassword)
{
try
{
string strDomain = System.Environment.UserDomainName; // modify
as required
using (LdapConnection objLDAP = new LdapConnection(strDomain))
{
objLDAP.AuthType = AuthType.Kerberos;
objLDAP.Bind(new NetworkCredential(pstrUser, pstrPassword,
strDomain));
return true;
}
}
catch (System.Runtime.InteropServices.COMException)
{
return false;
}
catch (Exception)
{
return false;
}
}
>
>
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
>
>
"Julia B" <JuliaB@dotnet.itags.org.discussions.microsoft.comwrote in message
news:028770DD-09FE-49BB-9C85-B3536C9B59F6@dotnet.itags.org.microsoft.com...
Quote:
Originally Posted by
I should have explained that I'm using .net 1.1.
Ah - yes you should... :-) v2.0 has been out for almost two years now, and
the next version is just round the corner, so if you don't explicitly say
you're not using the current version, people will automatically assume that
you are...
I would suggest that you ask in the microsoft.public.adsi.general newsgroup
for how to convert the code I posted back to v1.1 of the Framework...
Apologies, but I don't know enough about ADSI to help in this respect - in
fact, the code I gave you was pretty much pinched from Joe Kaplan, ADSI MVP
and absolute Active Directory guru...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
Mark, thanks again for your help and time on this! My aplogies again for not
mentioning the version issue - we're a bit slow here to upgrade! I will post
on the group you suggested.
Julia
"Mark Rae [MVP]" wrote:
Quote:
Originally Posted by
"Julia B" <JuliaB@dotnet.itags.org.discussions.microsoft.comwrote in message
news:028770DD-09FE-49BB-9C85-B3536C9B59F6@dotnet.itags.org.microsoft.com...
>
Quote:
Originally Posted by
I should have explained that I'm using .net 1.1.
>
Ah - yes you should... :-) v2.0 has been out for almost two years now, and
the next version is just round the corner, so if you don't explicitly say
you're not using the current version, people will automatically assume that
you are...
>
I would suggest that you ask in the microsoft.public.adsi.general newsgroup
for how to convert the code I posted back to v1.1 of the Framework...
>
Apologies, but I don't know enough about ADSI to help in this respect - in
fact, the code I gave you was pretty much pinched from Joe Kaplan, ADSI MVP
and absolute Active Directory guru...
>
>
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
>
>
"Julia B" <JuliaB@dotnet.itags.org.discussions.microsoft.comwrote in message
news:D7D55CFA-930F-4602-B19B-85E92F2C1C08@dotnet.itags.org.microsoft.com...
Quote:
Originally Posted by
My aplogies again for not mentioning the version issue -
we're a bit slow here to upgrade!
Make sure you don't get left behind...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
0 comments:
Post a Comment