Page 1 of 1 1
Topic Options
#149810 - 2005-10-12 06:55 PM UDF to verify user name
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
I am looking to verify that a username has been entered correctly by searching AD for the "exact" string as entered. I know that there must be a UDF for this, but cant seem to find anything.
_________________________
Today is the tomorrow you worried about yesterday.

Top
#149811 - 2005-10-12 07:01 PM Re: UDF to verify user name
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Try searching on LDAP.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#149812 - 2005-10-12 07:04 PM Re: UDF to verify user name
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
p.s. your location still says Alaska.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#149813 - 2005-10-12 07:27 PM Re: UDF to verify user name
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Found the fnLDAPQuery, and will give it a shot.

PS I updated my info.....
_________________________
Today is the tomorrow you worried about yesterday.

Top
#149814 - 2005-10-12 07:29 PM Re: UDF to verify user name
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
From one extreme to the other... Frozen Alaska to sun baked Arizona.

TranslateName() is another UDF you could look at.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#149815 - 2005-10-12 07:48 PM Re: UDF to verify user name
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Quote:

From one extreme to the other... Frozen Alaska to sun baked Arizona.






And Love every second of it
_________________________
Today is the tomorrow you worried about yesterday.

Top
#149816 - 2005-10-12 09:46 PM Re: UDF to verify user name
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Ok, still now working for some reason.

I am trying to use the fnLDAPQuery with the following code
Code:

$Name = FnLDAPQuery("samAccountName")

If AScan($Name,$textbox1.text) < 0
MessageBox("User ID not found","Notice",64)
$Label1.Width = 58
$Label1.Text = "User ID: "
$TextBox1.Visible = "True"
Exit (1)
EndIf



Where the user is typing a user name into the $TextBox1.Text field.

I have done a complete dump of the $Name array and all of the proper information appears as would be expected, however the ASCAN alway's returns a -1, even though I look at the dump of the $Name and can see the match.

As an example I have the AUser, the account is listed in the $Name, and when I ? the $textbox1.text it is = auser

What did I mess up this time?
_________________________
Today is the tomorrow you worried about yesterday.

Top
#149817 - 2005-10-12 10:24 PM Re: UDF to verify user name
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Well... I am not very good at writing queries and I see you aren't either.

That is why I suggested the TraslateName() UDF. IF you feed it a NetBIOS name, and ask it to translate to say... DN, you can then test the result returned in the array.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#149818 - 2005-10-12 10:27 PM Re: UDF to verify user name
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Your approach does not seem very efficient especially if you attempt this on a domain with many users.

You could even use the ADSI WinNT:// provider to bind to the expected account name. If you succeed then the account exists. Otherwise you will get an error.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#149819 - 2005-10-12 10:29 PM Re: UDF to verify user name
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Here is how I would code it.
Code:
break on
Call 'C:\KiXscripts\UDF\TranslateName.udf'
$RC = TranslateName(3, '', 3, @LDomain + '\LLigetfa', 1)
'RC[0] = ' + $RC[0] ?
'RC[1] = ' + $RC[1] ?
'RC[2] = ' + $RC[2] ?


And the result:
Code:
RC[0] = CN=LLigetfa,OU=Users,OU=FF,OU=CACC,DC=cacc,DC=local
RC[1] = 0
RC[2] = The operation completed successfully.

C:\KiXScripts>


Put in a bogus ID and the result becomes:
Code:
RC[0] =
RC[1] = -2147352567
RC[2] = COM exception error "Set" ((null) - (null)) [-2147352567/80020009]

C:\KiXScripts>

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#149820 - 2005-10-12 10:32 PM Re: UDF to verify user name
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I guess I was thinking that I wanted to do more with the result anyway. After all... what is there to do with a username besides verify it?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#149821 - 2005-10-12 10:41 PM Re: UDF to verify user name
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Yes...there would seem to be a next step after someone enters a user ID. Maybe you should just proceed with whatever you intend and trap the resulting error if the process fails.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#149822 - 2005-10-12 10:41 PM Re: UDF to verify user name
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Quote:

You could even use the ADSI WinNT:// provider to bind to the expected account name




not sure how to implement this. If you could point me in the correct direction...

Quote:

RC[0] = CN=LLigetfa,OU=Users,OU=FF,OU=CACC,DC=cacc,DC=local




Except then I would have to break it up even further for the comparison as all I need is the CN=

The people that will be using this only have the User Logon Information. So I need to be able to compare the username to username in AD somehow.

As for changing behavior of the users, it is help desk, so...
_________________________
Today is the tomorrow you worried about yesterday.

Top
#149823 - 2005-10-12 11:09 PM Re: UDF to verify user name
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
I think you should stick with fnLDAPQuery(). If you get the hang of it, you'll find it a very powerful tool for querying Active Directory.

Code:

$aWhat = "sAMAccountname","ADsPath"
$sSAM = $textbox1.text
$sWhere = "(&(objectCategory=person)(objectClass=user)(SAMAccountname="+$sSAM+"))"
$aResults = fnLDAPQuery($aWhat,,$sWhere)
If UBound($aResults) < 0
MessageBox("User ID not found","Notice",64)
$Label1.Width = 58
$Label1.Text = "User ID: "
$TextBox1.Visible = "True"
Exit (1)
Else
$aResults[0,0] ? ; The user's sAMAccountname
$aResults[0,1] ? ; The user's ADsPath
EndIf


Top
#149824 - 2005-10-12 11:11 PM Re: UDF to verify user name
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Quote:

Maybe you should just proceed with whatever you intend



I can do (and have already) that, just that my manager asked if we could verify their spelling of the users name and like an ID10T, I said sure.....

And yes I am doing something after I verify the name, this is a script being used to del profiles off of terminal servers.
_________________________
Today is the tomorrow you worried about yesterday.

Top
#149825 - 2005-10-12 11:33 PM Re: UDF to verify user name
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Chris,

Thanks that worked perfectly. Just need to learn how to write them query's now...
_________________________
Today is the tomorrow you worried about yesterday.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1471 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.07 seconds in which 0.028 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org