I tried your code, and it works fine for me. However, the password
"Testpwd" should actually result in an error because the IS_STRONG()
validator defaults to number=1 (i.e., at least one number in the password),
and you didn't change that default. So, you should get an error on the
password field. If the error isn't showing up, perhaps there's a problem
with your view code. Have you created a custom form in the HTML?
Anthony
On Tuesday, March 27, 2012 11:53:37 PM UTC-4, cyan wrote:
>
>
> Thanks for the pointer. Anthony.
>
> So now I have the following in my controller:
>
> def register():
> form = SQLFORM.factory(
> Field('email', requires=[IS_NOT_EMPTY(), IS_EMAIL(forced=
> '^.*\.edu(|\..*)$',
> error_message='email must be .edu address')]),
> Field('pwd', requires=[IS_NOT_EMPTY(), IS_STRONG(min=6, special=0, upper=
> 1,
> error_message='minimum 6 characters, and at least 1 uppercase character'
> ), CRYPT()]),
> Field('re_pwd', requires=IS_EXPR('value==%s' % repr(request.vars.get(
> 'pwd', None)),
> error_message='passwords do not match')))
>
> if form.process().accepted:
> session.email = form.vars.email
> session.pwd = form.vars.pwd
> redirect(URL('registered'))
> return dict(form=form)
>
>
> And, for testing, I input the following:
>
> [email protected]
>
> Testpwd
>
> Testpwd
>
>
> I didn't get any error messages, so presumably all three validations went
> fine. However, using a debugger revealed that form.accepted is still None
> after calling process() on the form. I wonder what went wrong here. Thanks.
> On Tuesday, March 27, 2012 5:54:02 PM UTC-4, Anthony wrote:
>>
>> Here's how auth.register() does it (slightly edited):
>>
>> requires=IS_EXPR('value==%s' % repr(request.vars.get('password', None)),
>> error_message="Password fields don't match")
>>
>> Anthony
>>
>> On Tuesday, March 27, 2012 5:40:29 PM UTC-4, cyan wrote:
>>>
>>>
>>> Hi group,
>>>
>>> How do I enforce some simple validation for passwords matching on a form
>>> in a controller? All I want to do is to check the second password is the
>>> same as the first one, and here is some code I've come up so far:
>>>
>>> form = SQLFORM.factory(
>>> Field('email', requires=IS_NOT_EMPTY()),
>>> Field('pwd', requires=[IS_NOT_EMPTY(), IS_STRONG(min=6, special=0,upper
>>> =1), CRYPT()]),
>>> Field('re_pwd', requires=IS_MATCH(???)))
>>>
>>> I am attempting to use the validator 'IS_MATCH()' for the second
>>> password, but not sure how I reference the the input in the first password
>>> field of the same form. Any suggestion would be welcome. Thanks.
>>>
>>