Advertisement

12.12.2007 at 11:13AM PST, ID: 23019242
[x]
Attachment Details

Help with pwValidator.cfc (Custom password validation tag/cfc)

Asked by BongSoo in Cold Fusion Markup Language, ColdFusion Studio, WebApplications

Tags: , ,

I hope I can explain this adequately. Basically I am trying to incorporate a custom tag/cfc into my code. The snippets below show the base tag and a test page that it works fine on.

What I have is an included template for a registration form that incorporates that tag. On the page that it is included in, I want to run a <cfswitch> check of the structure that is returned from the cfc. The cfc variable/structure is called pwStatus, and has two keys, message and status.

I cannot figure out how to pass them on to the next stage. Its almost a 'chicken or the egg' scenario. I tried putting them into session variables, but then it retains the first attempt - subsequent attempts only show the first attempt. I need it to pass the new version each time. This is sort of urgent, so 500 points!!!Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
######## Original CFC code and test page code  #############
 
<!--- loginPage.cfm --->
<html>
<head>
<title>Login</title>
</head>
 
<body>
<cfif isDefined("form.pw1") and (Len(Trim(form.pw1)) GT 0 and
Len(Trim(form.pw2)) GT 0)>
<cfinvoke component="pwValidator" method="validate" returnvariable="pwStatus">
<cfinvokeargument name="password1" value="#form.pw1#">
<cfinvokeargument name="password2" value="#form.pw2#">
<cfinvokeargument name="caseSensitivity" value="True">
</cfinvoke>
<!--- The return variable, pwStatus, is a structure. Its keys are Message and
Status. --->
<cfdump var="#pwStatus#">
</cfif>
<pre>
<cfform action="#cgi.script_name#" method="post">
<!--- <p>User name: <cfinput type="text" name="user_name"
required="Yes" message="You must give a user name"></p> --->
<p>password: <cfinput type="Password" name="pw1" required="Yes"
message="You must give a password"></p>
<p>confirmation password: <cfinput type="Password" name="pw2" required="Yes"
message="You must give a confirmation password"></p>
<p><cfinput type="Submit" name="sbmt" value="validate password"></p>
</cfform>
</pre>
</body>
</html>
 
 
<!--- pwValidator.cfc --->
<cfcomponent displayname="passwordValidator" hint="Contains method for
password validation.">
<cffunction name="validate" output="no" returntype="struct">
<cfargument name="password1" type="string" required="yes">
<cfargument name="password2" type="string" required="yes">
<cfargument name="caseSensitivity" type="boolean" required="no"
default="true">
<!--- Initialize variables --->
<cfset pw = "#Trim(arguments.password1)#">
<cfset s = Len(pw)>
<cfset pwCheck = StructNew()>
<cfset pwCheck.status = false>
<!--- No password entered --->
<cfif s EQ 0>
<cfset pwCheck.message="You must give a password">
<cfreturn pwCheck>
</cfif>
<!--- Password too short --->
<cfif s LT 5>
<cfset pwCheck.message="Password too short. Use 5 or more letters and
numbers.">
<cfreturn pwCheck>
</cfif>
<!--- Password too long --->
<cfif s GT 15>
<cfset pwCheck.message="Password too long. Use at most 15 letters and
numbers.">
<cfreturn pwCheck>
</cfif>
<!--- Password and confirmation password do not match
(case-insensitive)--->
<cfswitch expression="#caseSensitivity#">
<cfcase value=false>
<CFIF CompareNoCase(pw, "#Trim(arguments.password2)#") NEQ 0>
<cfset pwCheck.message="The two passwords do not match">
<cfreturn pwCheck>
</CFIF>
</cfcase>
<!--- (with case-sensitivity switched on) --->
<cfcase value=true>
<CFIF Compare(pw, "#Trim(arguments.password2)#") NEQ 0>
<cfset pwCheck.message="The two passwords do not match">
<cfreturn pwCheck>
</CFIF>
</cfcase>
</cfswitch>
<!--- Use regular expressions to check that only alphanumeric characters are
in pw--->
<cfif REFindNoCase("[^[:alnum:]]",pw,1,false) NEQ 0>
<cfset pwCheck.message="Password may contain only numbers, letters in upper
or lower case and no spaces.">
<cfreturn pwCheck>
</cfif>
<!--- pw good if it has passed preceding tests --->
<cfset pwCheck.status = true>
<cfset pwCheck.message = "OK">
<cfreturn pwCheck>
</cffunction>
</cfcomponent>
 
 
 
########### my code ############
 
This is the included registration form, and shows my attemps to pass the variables through session variables. Even though I use the cfparam to 'reset' the variable, it doesn't seem to work and holds only the 'first' attempt variable.
 
<!--- regform.cfm --->
 
<cfparam name = "session.pwStatus.status" default = "false">
<cfparam name = "session.pwStatus.message" default = "Ben is an idiot.">
 
<div id="regform" style="float:right; margin:20px;">
 
<!--- loginPage.cfm --->
 
 <cfif isDefined("form.pw1") and (Len(Trim(form.pw1)) GT 0 and
Len(Trim(form.pw2)) GT 0)>
        <cfinvoke component="pwValidator" method="validate" returnvariable="session.pwStatus">
                <cfinvokeargument name="password1" value="#form.pw1#">
                <cfinvokeargument name="password2" value="#form.pw2#">
                <cfinvokeargument name="caseSensitivity" value="True">
        </cfinvoke>
 <!--- The return variable, pwStatus, is a structure. Its keys are Message and
Status.
      <cfdump var="#session.pwStatus#">  --->
 </cfif>
 
 <cfform action="#cgi.script_name#" method="post" name="regform">
 <cfinput type="hidden" name="formid" value="regform1">
 
 	<table>
	<TR><TH COLSPAN="2">Create A New Account:</TH></TR>
    
		<tr>
			<td align="left"><b>Enter Your Desired User Name:</b>&nbsp;</td><td><cfinput type="text" name="regusername" required="Yes" message="You must give a user name" size="30"></td>
		</tr>
        <tr>
			<td align="left"><b>Enter Your Desired Password:</b>&nbsp;</td><td><cfinput type="Password" name="pw1" required="Yes" message="You must give a password" size="30"></td>
		</tr>
		<tr>
			<td align="left"><b>Confirm Your Desired Password:</b>&nbsp;</td><td><cfinput type="Password" name="pw2" required="Yes" message="You must give a confirmation password" size="30"></td>
		</tr>
 
		<tr>
			<td><cfinput type="Submit" name="sbmt" value="Create New Account">
			 </td><td>&nbsp;</td>
		</tr>
	</table>
 </cfform>
 
</div>
 
 
 
This is just a snippet of the page that the above is included in, but you can get a glimpse of what I am trying to do. Basically the name of the form (passed by a hidden field) determines whether it is a user logging in (works fine) or a new user submitting a new registration form (see above). If the 
 
   <cfcase value="regform1">
	<!--- check password validation is working --->
	
<h1>At least its loading this</h1> <!--- just a message to make sure its going to the next step --->
 
<cfoutput>#session.pwStatus.status#, #session.pwStatus.message#</cfoutput>
<cfdump var="#session.pwStatus#">
 
<cfswitch expression="#session.pwStatus.status#">
	<cfcase value="true">
		<h2>Password is ok</h2>
<!--- insert code here for what to do next --->
	</cfcase>
	<cfcase value="false">
		<h2>Password is  not ok</h2>
		<cfoutput>#session.pwStatus.message#</cfoutput>
<!--- send them back to registration form --->
	</cfcase>	
	<cfdefaultcase>
		<h1>Not passing form.pwmessage</h1>
	</cfdefaultcase>
</cfswitch> --->
 
<cfabort>
[+][-]12.12.2007 at 11:50AM PST, ID: 20459597

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Cold Fusion Markup Language, ColdFusion Studio, WebApplications
Tags: cfswitch, password, validation
Sign Up Now!
Solution Provided By: _agx_
Participating Experts: 1
Solution Grade: A
 
 
[+][-]12.12.2007 at 12:19PM PST, ID: 20459796

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12.12.2007 at 12:31PM PST, ID: 20459903

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.12.2007 at 12:34PM PST, ID: 20459922

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12.12.2007 at 12:39PM PST, ID: 20459963

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.12.2007 at 12:39PM PST, ID: 20459964

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628