3 <script type="text/javascript"
4 src="../../../dojo/dojo.js"
5 djConfig="isDebug: true, parseOnLoad: true">
7 <script type="text/javascript">
8 dojo.require("doh.runner");
9 dojo.require("dojo.parser");
10 dojo.require("dojox.form.PasswordValidator");
11 dojo.require("dijit.form.Button");
12 dojo.require("dijit.form.Form");
14 dojo.addOnLoad(function(){
17 function test_setDisabled(t){
18 valid1.setAttribute("disabled", true);
19 t.t(dojo.every(dojo.query("[widgetId]",
20 valid1.domNode).map(function(i){
21 return dijit.byNode(i);
22 }), function(i){return i.disabled;}));
23 valid1.setAttribute("disabled", false);
24 t.t(dojo.every(dojo.query("[widgetId]",
25 valid1.domNode).map(function(i){
26 return dijit.byNode(i);
27 }), function(i){return !i.disabled;}));
29 function test_isValid(t){
31 dijit.byId("nv1").setValue("test");
32 dijit.byId("vv1").setValue("Test");
34 dijit.byId("vv1").setValue("test");
37 t.is({password: ""}, form6.getValues());
38 dijit.byId("nv6").setValue("test");
40 t.is({password: ""}, form6.getValues());
41 dijit.byId("vv6").setValue("test");
43 t.is({password: "test"}, form6.getValues());
45 function test_getValue(t){
46 dijit.byId("nv1").setValue("test");
47 dijit.byId("vv1").setValue("Test");
48 t.is({password: ""}, form1.getValues());
49 dijit.byId("vv1").setValue("test123");
50 dijit.byId("nv1").setValue("test123");
51 t.is({password: "test123"}, form1.getValues());
53 function test_oldPW(t){
54 dijit.byId("nv2").setValue("test");
55 dijit.byId("vv2").setValue("test");
57 dijit.byId("ov2").setValue("oldpw4");
59 dijit.byId("ov2").setValue("oldpw2");
62 function test_getOldValue(t){
63 t.is({password: "test"}, form2.getValues());
64 dijit.byId("nv3").setValue("test");
65 dijit.byId("vv3").setValue("test");
66 dijit.byId("ov3").setValue("oldpw4");
67 t.is({password: "", oldPassword: ""}, form3.getValues());
68 dijit.byId("ov3").setValue("oldpw3");
69 dijit.byId("vv3").setValue("Test");
70 t.is({password: "", oldPassword: ""}, form3.getValues());
71 dijit.byId("vv3").setValue("test");
72 t.is({password: "test", oldPassword: "oldpw3"}, form3.getValues());
74 function test_getValuesInTable(t){
75 dijit.byId("nv4").setValue("test");
76 dijit.byId("vv4").setValue("test");
77 dijit.byId("ov4").setValue("oldpw4");
78 t.is({password: "test"}, form4.getValues());
79 dijit.byId("nv5").setValue("test");
80 dijit.byId("vv5").setValue("test");
81 dijit.byId("ov5").setValue("oldpw5");
82 t.is({password: "test", oldPassword: "oldpw5"}, form5.getValues());
89 <link rel="stylesheet" type="text/css" href="../../../dijit/themes/tundra/tundra.css">
90 <link rel="stylesheet" type="text/css" href="../../../dijit/tests/css/dijitTests.css">
93 <h1 class="testTitle">Test: dojox.form.PasswordValidator</h1>
94 <h2>Automated test</h2>
95 <h4 class="testSubtitle">No old password</h4>
96 <form dojoType="dijit.form.Form" jsId="form1">
97 <div dojoType="dojox.form.PasswordValidator" jsId="valid1" name="password">
98 <label>Password: <input type="password" id="nv1" pwType="new" /></label><br>
99 <label>Validate: <input type="password" id="vv1" pwType="verify" /></label><br>
103 <h4 class="testSubtitle">Old password (hard-coded to "oldpw2") - not passed to getValues</h4>
104 <form dojoType="dijit.form.Form" jsId="form2">
105 <div dojoType="dojox.form.PasswordValidator" jsId="valid2" name="password">
106 <script type="dojo/method" event="pwCheck" args="password">
108 NOTE: Do NOT EVER EVER EVER do this sort of a check!!!
110 This is only as an example. You will probably want to
111 override the pwCheck function to callback to a server to
112 verify the password (the callback will need to be
113 syncronous) - and it's probably a good idea to validate
114 it again on form submission before actually doing
115 anything destructive - that's why the "oldName" value
118 And don't just fetch the password from the server
119 either :) Send the test password (probably hashed, for
120 security) and return from the server a status instead.
122 Again - DON'T DO THIS - it is HORRIBLY INSECURE!!!!
124 Security is left as an exercise to the reader :)
126 return password === "oldpw2";
128 <label>Old Password: <input type="password" id="ov2" pwType="old" /></label><br>
129 <label>Password: <input type="password" id="nv2" pwType="new" /></label><br>
130 <label>Validate: <input type="password" id="vv2" pwType="verify" /></label><br>
134 <h4 class="testSubtitle">Old password (hard-coded to "oldpw3") - passed to getValues</h4>
135 <form dojoType="dijit.form.Form" jsId="form3">
136 <div dojoType="dojox.form.PasswordValidator" jsId="valid3" name="password" oldName="oldPassword">
137 <script type="dojo/method" event="pwCheck" args="password">
138 console.log("Checking " + password);
139 return password === "oldpw3";
141 <label>Old Password: <input type="password" id="ov3" pwType="old" /></label><br>
142 <label>Password: <input type="password" id="nv3" pwType="new" /></label><br>
143 <label>Validate: <input type="password" id="vv3" pwType="verify" /></label><br>
147 <h4 class="testSubtitle">In Table, Old password (hard-coded to "oldpw4") - not passed to getValues</h4>
148 <form dojoType="dijit.form.Form" jsId="form4">
149 <div dojoType="dojox.form.PasswordValidator" jsId="valid4" name="password">
150 <script type="dojo/method" event="pwCheck" args="password">
151 return password === "oldpw4";
155 <td><label for="ov4">Old Password:</label></td>
156 <td><input type="password" id="ov4" pwType="old" /></td>
159 <td><label for="nv4">Password:</label></td>
160 <td><input type="password" id="nv4" pwType="new" /></td>
163 <td><label for="vv4">Validate:</label></td>
164 <td><input type="password" id="vv4" pwType="verify" /></td>
170 <h4 class="testSubtitle">In Table, Old password (hard-coded to "oldpw5") - passed to getValues</h4>
171 <form dojoType="dijit.form.Form" jsId="form5">
172 <div dojoType="dojox.form.PasswordValidator" jsId="valid5" name="password" oldName="oldPassword">
173 <script type="dojo/method" event="pwCheck" args="password">
174 return password === "oldpw5";
178 <td><label for="ov5">Old Password:</label></td>
179 <td><input type="password" id="ov5" pwType="old" /></td>
182 <td><label for="nv5">Password:</label></td>
183 <td><input type="password" id="nv5" pwType="new" /></td>
186 <td><label for="vv5">Validate:</label></td>
187 <td><input type="password" id="vv5" pwType="verify" /></td>
193 <h4 class="testSubtitle">No old password, not required</h4>
194 <form dojoType="dijit.form.Form" jsId="form6">
195 <div dojoType="dojox.form.PasswordValidator" required="false" jsId="valid6" name="password">
196 <label>Password: <input type="password" id="nv6" pwType="new" /></label><br>
197 <label>Validate: <input type="password" id="vv6" pwType="verify" /></label><br>
201 <button dojoType="dijit.form.Button">
202 <script type="dojo/method" event="onClick">
203 dojo.forEach([form1, form2, form3, form4, form5, form6], function(i){
204 console.dir(i.getValues());
209 <button dojoType="dijit.form.Button">
210 <script type="dojo/method" event="onClick">
211 valid5.setAttribute("disabled", !valid5.disabled);