View comments | RSS feed
Contents > CFML Reference > ColdFusion Functions > IsUserInRole PreviousNext

IsUserInRole

Determines whether an authenticated user belongs to the specified Role.

True, if the authenticated user, belongs to the specified Role; False, otherwise.

Authentication functions, Decision functions

IsUserInRole("role_name")

GetAuthUser, cflogin, cfloginuser, Securing Applications in Developing ColdFusion MX Applications

ColdFusion MX: Added this function.

Parameter

Description

role_name

Name of a security role

Role names are case-sensitive.

To check if a user is in multiple roles, specify them in a comma delimited list, such as "Admin,HR". Lists with multiple roles cannot contain spaces as separators; for example, do not use "Admin, HR".

<cfif IsUserInRole("Admin") > 
   <cfoutput>Authenticated user is an administrator</cfoutput> 
<cfelse IsUserInRole("User") > 
   <cfoutput>Authenticated user is a user</cfoutput> 
</cfif>

Contents > CFML Reference > ColdFusion Functions > IsUserInRole PreviousNext

ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6.1

Comments are no longer accepted for ColdFusion MX 6.1. ColdFusion 8 is the current version.

Comments


CF_HELP said on Feb 4, 2005 at 6:44 AM :
<cfelse IsUserInRole("User") >

The above line should be
<cfelseif IsUserInRole("User") >


IF is missing, It can't be <cfelse> it should be <cfelseif
tonyjk3 said on Mar 31, 2005 at 8:44 AM :
When using IsUserInRole to see if a user has rights to view a certain page, can you use multiple roles?

<cfif IsUserInRole("admin,editor")>
content that can be edited
</cfif>

Or can you only validate one role at a time?

<cfif IsUserInRole("admin")>
content
</cfif>

Everytime I try and validate two roles, it doesn't work. I have some parts of my site that the admin and the editor have the same rights.
boughtonp said on Jun 21, 2005 at 2:46 AM :
If you use two roles, the user must be in BOTH roles -- ie: an Admin AND an Editor -- so you would presumably want to use this:
<cfif IsUserInRole("admin") OR IsUserInRole("editor")>...</cfif>
No screen name said on Apr 19, 2006 at 6:03 PM :
if you want to pass a list of Roles to the function and have it return TRUE if it matches ANY Role in the list, you will need to write a UDF. Something like this will work:

function UserHasAccess(r){
var roles = listToArray(r);
for(x=1;x LTE arrayLen(roles);x=x+1){
if(isUserInRole(roles[x])){
return true;
}
}
return false;
}

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6.1/htmldocs/funct142.htm