循环哈希表并比较值 [英] Looping through hashtable and comparing values

查看:92
本文介绍了循环哈希表并比较值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好


我正在创建AD中用户列表的哈希表。键是UserID和

密码。我想遍历表格来比较用户ID和密码

与用户输入的值。理想情况下,我想要浏览

记录,直到找到一个与输入的UserID匹配,然后

比较密码。


我用Google搜索了,我真的找不到任何如何做到这一点的例子。


任何人都有任何想法?提前致谢!


Julia

解决方案

尝试:
http://msdn2.microsoft.com/en-us/lib。 ..e_members.aspx


特别包含(键)和项目(键)?另外请详细说明你遇到的

特定问题...


(看起来不清楚,但你似乎暗示你可能有多个用户

具有相同的ID但密码不同?你确定会发生这种情况

?!)


-

Patrice


" Julia B" < Ju **** @discussion.microsoft.comaécritdansle message de

news: 1C *********************** ***********@microsoft.com ...


大家好


我正在创建AD中用户列表的哈希表。键是UserID和

密码。我想遍历表格来比较用户ID和用户输入的值的b / b
密码

。理想情况下,我想要浏览

记录,直到找到一个与输入的UserID匹配,然后

比较密码。


我用Google搜索了,我真的找不到任何如何做到这一点的例子。


任何人都有任何想法?提前致谢!


Julia



" Julia B" < Ju **** @ discuss.microsoft.com写信息

新闻:1C ************************ ********** @ microsof t.com ...


我正在创建AD中用户列表的哈希表。键是UserID和

密码。我想遍历表格来比较用户ID和用户输入的值的b / b
密码

。理想情况下,我想要浏览

记录,直到找到一个与输入的UserID匹配,然后

比较密码。


我用Google搜索了,我真的找不到任何如何做到这一点的例子。


任何人都有任何想法?提前致谢!



有点疑惑...


虽然用户密码存储在ActiveDirectory中,但你当然不能
以与例如相同的方式检索它们你可以检索用户的电子邮件

地址等...


你从哪里获得用户名和密码来填充你的

Hashtable ......?

-

Mark Rae

ASP.NET MVP
http://www.markrae.net


< blockquote>对不起,让我更具体一点。不,不会有多个用户使用相同ID的

。我只是想根据用户输入的文本找到一个用户。我的

问题是我似乎无法弄清楚如何浏览哈希表

" rows"。 Hashtable没有行属性,所以你如何循环?或者

你循环通过键吗?如果是这样,他们宣称是什么?即


dim key为????

哈希表中的每个键

if key =" userid"然后

如果value =" xxxx"然后

结束如果

结束如果

next


问题是,虽然我是能够将变量声明为

散列表,散列表似乎没有成员/属性/函数

在我的intellisense上与它们相关联。代码如下。


希望更有意义。


Julia


公开函数ValidateIDPassword(ByVal enteredNetworkID As String,ByVal

enteredPassword As String)As Boolean

Dim usersTable As Hashtable = GetAllUsers(" ukntdc01.rcuk.com:389")

''现在遍历usersTable并检查是否有匹配的用户

''这是我不知道该怎么做的地方

结束函数


公共函数GetAllUsers(ByVal ldapServerName As String)As Hashtable

''此函数返回所有用于搜索的ldap广告用户在

验证的身份

Dim oRoot As DirectoryServices.DirectoryEntry = New

DirectoryServices.DirectoryEntry _

(" ; LDAP://& ldapServerName&

" / OU = EVOII,DC = rcuknet,DC = rockwellcollins,DC = com")

Dim oSearcher作为DirectoryServices.DirectorySearcher =新的

DirectoryServices.DirectorySearcher(oRoot)

Dim oResults As DirectoryServices.SearchResultCollection

Dim oResult As DirectoryServices.SearchResult

Dim RetArray作为Hashtable


oSearcher.PropertiesToLoad.Add(" SAMAccountName")

oSearcher.PropertiesToLoad.Add(" userPassword")

oResults = oSearcher.FindAll


每个oResult在oResult


如果不是

oResult.GetDirectoryEntry()。属性(" SAMAccount Name")。Value =""然后

RetArray.Add(UserID,

oResult.GetDirectoryEntry()。属性(SAMAccount名称)。值)

RetArray.Add(" Password",

oResult.GetDirectoryEntry()。Properties(" userPasswo rd")。Value)

End if


下一页


返回RetArray


结束功能


"帕特里斯"写道:


尝试:
http://msdn2.microsoft.com/en-us/lib...e_members.aspx


特别包含(键)和项目(键)?另外请详细说明你遇到的

特定问题...


(看起来不清楚,但你似乎暗示你可能有多个用户

具有相同的ID但密码不同?你确定会发生这种情况

?!)


-

Patrice


" Julia B" < Ju **** @ discussion.microsoft.coma ?? crit dans le message de

news: 1C ********************* *************@microsoft.com ...


大家好


我正在创建AD中用户列表的哈希表。键是UserID和

密码。我想遍历表格来比较用户ID和用户输入的值的b / b
密码

。理想情况下,我想要浏览

记录,直到找到一个与输入的UserID匹配,然后

比较密码。


我用Google搜索了,我真的找不到任何如何做到这一点的例子。


任何人都有任何想法?提前致谢!


Julia




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

解决方案

Try :
http://msdn2.microsoft.com/en-us/lib...e_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" <Ju****@discussions.microsoft.coma écrit dans le message de
news: 1C**********************************@microsoft.com...

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" <Ju****@discussions.microsoft.comwrote in message
news:1C**********************************@microsof t.com...

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("SAMAccount Name").Value = "" Then
RetArray.Add("UserID",
oResult.GetDirectoryEntry().Properties("SAMAccount Name").Value)
RetArray.Add("Password",
oResult.GetDirectoryEntry().Properties("userPasswo rd").Value)
End If

Next

Return RetArray

End Function

"Patrice" wrote:

Try :
http://msdn2.microsoft.com/en-us/lib...e_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" <Ju****@discussions.microsoft.coma ??crit dans le message de
news: 1C**********************************@microsoft.com...

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




这篇关于循环哈希表并比较值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆