Forum for discussing general topics related to Couch.
6 posts Page 1 of 1
Dear Couchmembers,

We've been using couch for many years with much delight.
Now we're working on a project where the company has specific demands for user passwords companywide. They want to expand this to their website admins.
Passwords must contain:
- at least 8 charcaters
- at least 1 special charcter
- at least 1 number
- at least 1 capital.

How could we create this?

I'd suggest doing the following -
1. Activate 'Extended Users' (
2. Use only the 'login' template (ignore the remaining four templates).

Once you have tested that the login template replaces the default Couch login page, you may style it as you wish.
More importantly, since it is an ordinary Couch template, you can tweak the code within it - specifically, you can add a 'validator' (regex or your own PHP function) to the 'k_user_pwd' input -
Code: Select all
<cms:input type='password' name='k_user_pwd' />

The validator can enforce the kind of restrictions you mentioned.

Hope this helps.
Thanks KK!

I've got it working with the simple cat|dog regex example from the docs (

But cannot make it work with my more extended regex (I'm no regex hero, which is probably the issue here).

Code: Select all
<cms:input placeholder="Password"  name='extended_user_password' type='password' validator='regex:^(?\=.*[a-z])(?\=.*[A-Z])(?\=.*\d)(?\=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$' separator='#' val_separator=':' />

Could you help me out?
Hi Saskia,

Working with regex can be quite frustrating.
I find it easier to debug things when I use a simple PHP function as validator instead.

@orbital was recently struggling with identifying curse-words in one of his forms and I suggested him this -

It is pretty easy to use normal PHP functions as validators -
For your use-case, you can put the following in your kfunctions.php -
Code: Select all
function validate_no_bad_words( $field, $args ){
    $data = trim( $field->get_data() );
    $regex = '/\b(ass|dog|bitch)\b/i';

    if( preg_match($regex, $data) ){
        return KFuncs::raise_error( "No bad words please!" );

The code above defines a custom validator named 'validate_no_bad_words' (a simple PHP function actually) which then can be used as follows -
Code: Select all
<cms:editable type='textarea' name='my_textarea' validator='validate_no_bad_words' />


Could you please try using the suggested solution above?
Of course, I'll be happy to help in case you still have trouble with this issue.

Oh great!

This worked like a charm! I'll post the code I ended up using for anyone else who's looking for this:

Code: Select all
function password_checker( $field, $args ){
    $data = trim( $field->get_data() );

    $regex = "/(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/";

    if( preg_match($regex, $data) ){

    } else{
        return KFuncs::raise_error( 'Uw wachtwoord moet bestaan uit ten minste: 8 karakters, 1 hoofdletter, 1 getal en 1 speciaal teken.' . $data );

Registration form
Code: Select all
<cms:if k_success>
   _invalidate_cache   ='0'
   extended_user_password   = frm_extended_user_password
<cms:input name='extended_user_password' type='password' validator='password_checker'  />
Thanks Saskia :)
6 posts Page 1 of 1