AllExperts > Experts 
Search      
Active Server Pages Programming (ASP)
Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More Active Server Pages Programming (ASP) Answers
Question Library

Ask a question about Active Server Pages Programming (ASP)
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Srini Nagarajan
Expertise
I can answer any kind of questions in ASP.NET, C#, VB.NET, SharePoint 2007, ASP, Coldfusion, Powerbuilder 7.00 / 8.00, JAVA servlets, MS SQL 2000 / MSSQL7, Sybase

Experience
Contact me if you need any custom development on ASP.NET, ASP, SharePoint 2007, Coldfusion, Powerbuilder.
 
   

You are here:  Experts > Computing/Technology > Business Software > Active Server Pages Programming (ASP) > Expanding the LOGON_USER to full username

Active Server Pages Programming (ASP) - Expanding the LOGON_USER to full username


Expert: Srini Nagarajan - 6/24/2005

Question
Thanks for your reply Srini; but that is not what I'm looking for.

The 2 methods you mentioned (instr and split) will provide the login id of the user but not the full name (example from your reply: I want the asp code to return "Srini Nagarajan"-the full name registered against login id "SRINI"-when you log in as SRINI to domain/computer PSSP.

-Thanks in advance,
Parag P. Doke
-------------------------
Followup To
Question -
Hi Srini!
I a newbie at ASP and I am trying to find out the full name of the user who has logged in to my server. I'm using the IIS on Windows 2000 Prof. and my directory security has 2 options checked:
1) Basic Authentication (password is sent in clear text)
2) Integrated windows authentication
I was able to get the username in the format <DOMAIN>/<USER_NAME> using Request.ServerVariables("LOGON_USER").
What I want to know is how to get the first name and last name of the user from the network.

Please let me know if you need more info. Thanks in advance,
Parag P. Doke
Answer -
Hi

Here is the simpe code (you can do it 2 ways)


'displays:  PSSP\SRINI when I login
Response.Write(Request.ServerVariables("LOGON_USER"))

Method 1

'To get only the username...
Dim strNTUser, iPos
strNTUser = RTrim(Request.ServerVariables("LOGON_USER"))
iPos = Len(strNTUser) - InStr(1, strNTUser,"\",1)
strNTUser = Right(strNTUser, iPos)


Method 2

Dim arrSomething, strNTUser
arrSomething = split(Request.ServerVariables("LOGON_USER"),"\")
strNTUser = arrSomething(1)


Happy Programming!!

Srini


Answer
hi

Here is the sample code give a try

<%
  '''''''''''''''''''''''''''''''''''''''''''''''''
  ' ADSI User Authentication Script
  ' Peter A. Bromberg  01/26/2001
  '''''''''''''''''''''''''''''''''''''''''''''''''
   ' Test here for a form post ...
  if request("GETUSER") = "" Then
   ' write out the test form
     With Response
     .write "<FORM ACTION=USER.ASP METHOD=POST>"
     .Write "<INPUT TYPE=TEXT NAME=oDomain>ENTER DOMAIN<BR>"
     .write "<INPUT TYPE=TEXT NAME=oUSer>ENTER USER NAME TO CHECK<BR>"
     .write "<INPUT TYPE=PASSWORD NAME=oPassword>ENTER USER PASSWORD<BR>"
     .Write "<INPUT TYPE =SUBMIT NAME=GETUSER VALUE=CHECK>"
     .write "</FORM>"
     end with
  
  else
  ' Form was autopostback, grab the form variables ...
       oDomain= Request("oDomain")
       oUser = Request("oUser")
       oPassword = Request("oPassword")
' begin "Kludge" VBScript error trapping  (see Javascript version for
try / catch handling)
on error resume next
' Set reference to the ADSI interface to NT User Manager ...
Set objUser = GetObject("WinNT://" & oDomain & "/" & oUser )

  if err.number <> 0 then
     Response.write "Login Error---"
     Response.end
  end if
  If len(objUser.FullName) < 1 then
        response.write "User Not Found!"
        response.end
  else

on error resume next
' We verify the user password by using the ChangePassword method to change
' the password back to itself.
' Since this requires that first parameter password be correct, it's an easy'  way to circumvent the fact
' that NT won't give actual access to the user's password to make a comparison. ' Be aware that on some systems,
' Admin policy settings may force the password
' to have to be changed after X number of uses
' of this method...

 objUser.ChangePassword  oPassword, oPassword
  if err.number <> 0 then

     Response.write" BAD PASSWORD!"
     Response.end
  else  

' Now write out the ADSI User object properties that are supported by Windows 2000 ...

With Response
   .write "USER AUHTENTICATED!<BR>"
  .write "Properties for user " & objUser.FullName & ": <BR>"
  .Write "AccountExpirationDate: " & objUser.AccountExpirationDate & "<BR>"
  .Write "BadLoginCount: " & objUser.BadLoginCount & "<BR>"
  .write "Description: " & objUser.Description & "<BR>"
  .write "HomeDirectory: " & objUser.HomeDirectory & "<BR>"
  .write "IsAccountLocked: " & objUser.IsAccountLocked & "<BR>"
  .write "LastLogin: " & objUser.LastLogin & "<BR>"
  .write "LastLogoff: " & objUser.LastLogoff & "<BR>"
  .write "LoginHours: " & objUser.LoginHours & "<BR>"
  .write "LoginScript: " & objUser.LoginScript & "<BR>"
  .write "LoginWorkstations: " & objUser.LoginWorkstations & "<BR>"
  .write "MaxStorage: " & objUser.MaxStorage &"<BR>"
  .write "PasswordExpirationDate: " & objUser.PasswordExpirationDate & "<BR>"
  .write "PasswordMinimumLength: " & objUser.PasswordMinimumLength & "<BR>"
  .write "PasswordRequired: " & objUser.PasswordRequired & "<BR>"
  .write "Profile: " & objUser.Profile & "<BR>"
   .write "Account Disabled: " & objUser.AccountDisabled
end with
  
end if   

end if

end if

  %>


Happy programming!

Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.