Skip to content

Password confirmation #104

Closed
Petah opened this Issue Jan 13, 2013 · 15 comments

9 participants

@Petah
Petah commented Jan 13, 2013

Is there a way to validate a password confirmation. I.e. validate that one field matches another?

@drgomesp
Respect member

Do you need just a simple comparison operation to match two strings?

Is it really necessary to use a Validation\Rule to do that?

@Petah
Petah commented Jan 15, 2013

@drgomesp well it would be nice to be consistent.

try {
    v::key('password_1', v::confirmation('password_2'))
     ->assert($request->post);
} catch (...) {}

Rather than

try {
    v::key('password_1')
     ->key('password_2')
     ->assert($request->post);
    if ($request->post['password_1'] !== $request->post['password_2']) {
        throw new ValidationException(...)
    }
} catch (...) {}
@drgomesp
Respect member

I really don't think this has anything to do with consistency.

Even know I like the second better, I do agree, though, it would be an interesting feature.

@augustohp
Respect member

My 2 cents on this: I think we could probably profit more of something like the assertions on PHPUnit, if we consider that we are missing an "equal" validator.

@drgomesp
Respect member

You've got a point there, @augustohp, since matching values are not only used on the password x confirmation context.

Maybe I'll contribute with that on the next few days.

@augustohp
Respect member
@alganet
Respect member
alganet commented Jan 17, 2013

We do have an "Equal" validator, but it only compares to external values:

v::key('password', v::equal($_POST['confirmation']))->validate($_POST);

Not a good approach though, 'cause the confirmation key may not be present. What we need is something generic that can apply validators between inner data pieces on the validation target. Something like:

//The key "password" should be equal the key "confirmation"
v::key('password', v::equal(v::key('confirmation')));

Another use case:

//The minimum value for the "end_date" key should be the "start_date" key.
v::key('end_date', v::min(v::key('start_date')));

What do you guys think?

@augustohp
Respect member

Completely missed that validator. That would serve the purpose, right @Petah ?

@alganet
Respect member
alganet commented Jan 18, 2013

@augustohp almost. The $_POST variable could still have a missing key, leading to a warning or notice.

@alganet
Respect member
alganet commented Jan 21, 2013

Anyone objects to this new feature? #104 (comment)

@henriquemoody
Respect member

+1

@CMCDragonkai

I need something like this in order to check if one of the values is smaller than the other value. Currently the other value may not exist, so what to do?

@nickl-
Respect member
nickl- commented Nov 8, 2013

+0 seems trivial to me and we have more pressing concerns but I am not immediately against it either

@augustohp augustohp modified the milestone: 0.6.1, 0.7.0 Feb 17, 2014
@augustohp augustohp modified the milestone: Backlog, 0.7.0 May 9, 2014
@rushes
rushes commented Nov 20, 2014

+1

having to use a bunch of if statements after using this nice validation library is really ugly, also this functionality is standard in all the other validation libraries ive used in other languages

@Whyounes

Has this functionality been added yet?

@henriquemoody henriquemoody modified the milestone: 1.0, Backlog Oct 12, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.