acornejo/jjv

Validating passwords

Closed this issue · 6 comments

I have two fields, password, and repeatPassword in my schema. Is it possible to specify that the passwords should match?

Hi @dmmalam, that would be possible with v5's constant which is not yet supported (see issue #28).

Traveling without a laptop this month, so can't answer in detail. However this may be possible through the experimental '$data' schema v5 support (jjv implements this, complete with json fragment uri).

Thanks.
Any chance for an example? It's pretty hard to find documentation for it.
I've tried a few things which didn't work.

Dharmesh Malam

On Sun, Aug 17, 2014 at 10:49 AM, Alex Cornejo notifications@github.com
wrote:

Traveling without a laptop this month, so can't answer in detail. However
this may be possible through the experimental '$data' schema v5 support
(jjv implements this, complete with json fragment uri).


Reply to this email directly or view it on GitHub
#34 (comment).

@dmmalam, as far as I can tell, you can't do exactly what you want without constant as @mike-marcacci points out. However, a workaround might be to wrap the repeatPassword in an array and use the enum like this:

var jjv = require('jjv');
var env = jjv();
var schema = { properties: { 'p': { enum: { $data: '1/r' } } } };
console.log(env.validate(schema, { p: 'abc', r: ['xyz'] })); // { validation: { p: { enum: true } } }
console.log(env.validate(schema, { p: 'abc', r: ['abc'] })); // null

Just added support for the constant proposal: https://github.com/json-schema/json-schema/wiki/constant-(v5-proposal)

Here is a simple sample schema:

{
    type: 'object',
    properties: {
        "password": { type: 'string' },
        "password_confirm": {constant: {$data: '1/password'}}
    }
}

Awesome, thanks so much!

Dharmesh Malam

On Wed, Aug 27, 2014 at 10:39 AM, Alex Cornejo notifications@github.com
wrote:

Closed #34 #34.


Reply to this email directly or view it on GitHub
#34 (comment).