CFLib.org – Common Function Library Project

getAuthUsername()

Last updated October 9, 2006

Version: 1 | Requires: ColdFusion 5 | Library: SecurityLib

 
Rated 0 time(s). Average Rating: 0

Description:
Users have various ways of specifying their username when logging onto a network. The formats can be: username@some.domain, domain\username, or even just username. This function returns the username portion of the cgi.auth_user or cgi.remote_user variables. If neither cgi variable contains a value, an empty string is returned.

Return Values:
Returns a string.

Example:

view plain print about
<cfoutput>
#getAuthUsername()#
</cfoutput>

Parameters:

No arguments.

Full UDF Source:

view plain print about
<!---
 Get the authenticated username from the cgi.auth_user or cgi.remote_user without the domain information.
 
 @return Returns a string. 
 @author Mike Tangorre (mtangorre@gmail.com) 
 @version 1, April 9, 2007 
--->

<cffunction name="getAuthUsername" returntype="string" output="false">
    
    <cfset var username = "" />
    
    <cfif len(trim(cgi.auth_user))>
    
        <cfset username = trim(cgi.auth_user) />
    
    <cfelseif len(trim(cgi.remote_user))>
    
        <cfset username = trim(cgi.remote_user) />
    
    <cfelse>
    
        <!--- no string to work with --->
        <cfreturn trim(username) />
    
    </cfif>
    
    <!--- check username@some.domain --->
    <cfif find("@",username)>
    
        <cfreturn listFirst(username,"@") />
    
    <!--- check domain\username --->
    <cfelseif find("\",username)>
    
        <cfreturn listLast(username,"\") />
    
    <!--- no domain --->
    <cfelse>
    
        <cfreturn trim(username) />
    
    </cfif>
    
</cffunction>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Tayo Akinmade Tayo Akinmade added
arrayTrim
4 day(s) ago

Will Belden Will Belden added
longTime
9 day(s) ago

James Sleeman James Sleeman added
quickSort
19 day(s) ago

Ben Forta Ben Forta added
GetHostAddress
22 day(s) ago

Top Rated

Darwan Leonardo Sitepu EksporSQLData
Rated 5.0, 16 time(s)

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 13 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson