-
Notifications
You must be signed in to change notification settings - Fork 830
feat: add IsStrongPassword decorator #1025
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@jhullse I just check code, its awesome! I just notice validate: (value, args): boolean => isStrongPassword(value, args.constraints[0]) arg can be undefined and it can throw error... maybe you can update line to? validate: (value, args): boolean => isStrongPassword(value, args?.constraints?.[0] ?? {}) |
@jhullse export interface IsStrongPasswordOptions {
...(prev interface code)
returnScore?: boolean;
pointsPerUnique?: number;
pointsPerRepeat?: number;
pointsForContainingLower?: number;
pointsForContainingUpper?: number;
pointsForContainingNumber?: number;
pointsForContainingSymbol?: number;
} in the definition of isStrongPassword If returnScore is true, then the function returns an integer score for the password rather than a boolean. so return type should be boolean or number export function isStrongPassword(
value: unknown,
options?: IsStrongPasswordOptions
): boolean | number {
...
} and decorator probably will look like this export function IsStrongPassword(
options?: IsStrongPasswordOptions,
validationOptions?: ValidationOptions
): PropertyDecorator {
return ValidateBy(
{
name: IS_STRONG_PASSWORD,
constraints: [options],
validator: {
validate: (value, args): boolean => {
const validationResult = isStrongPassword(
value,
args?.constraints?.[0] ?? {}
);
if (typeof validationResult == "boolean") {
return validationResult;
} else {
return validationResult > 0;
}
},
defaultMessage: buildMessage((eachPrefix) => {
return eachPrefix + "$property is not strong enough";
}, validationOptions),
},
},
validationOptions
);
} |
Thanks for the feedback @rpCal. I'd like to clarify some things before I change the code. About the first suggestion:
When I was implementing the decorator I realized that
But at the same time I looked at several decorators in https://github.com/typestack/class-validator/tree/develop/src/decorator and they were all implemented assuming that About the second suggestion:
When I was implementing the decorator the scoring part didn't seem to fit because if you use
which would cause the decorator to always return true even with weak passwords (assuming that |
I am eagerly awaiting this! Let's get this added ASAP - I know other developers who would be very interested in having this built in to class-validator. |
acb7de1
to
c6984bb
Compare
nice work @jhullse. after a few months, this is still not merged. i have checked this pr: remove changes in package.json will fix the conflicts. i really nead this feature. so to ask would u update it. great thanks to u. |
df26dbf
to
1856cb6
Compare
@Jogiter done. The problem was that Dependabot updated some dependencies. The original PR didn't change any dependencies so I basically rebased my fork and now things look good. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
2ef8ff0
to
0da8f89
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you are still interested in getting this merged, then please rebase to the latest develop.
16b2a5c
to
bf0632b
Compare
bf0632b
to
e5edb82
Compare
Did you close by accident? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the rebase! Tests and build are currently failing.
bae7140
to
3c334af
Compare
@NoNameProvided The version of |
Hey guys, really looking forward to this one - anyone able to merge it? Seems like it's all green :) |
3c334af
to
47f83c9
Compare
@NoNameProvided I believe there is a change request from you that is already fixed (tests were failing before but not anymore) but it is still blocking the PR. When you have time, could you take a look at it? I'm not sure if @braaar or @Jogiter can help with this |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Description
Add support to password strength validation.
Checklist
Update index.md
)develop
)npm run prettier:check
passesnpm run lint:check
passesFixes
fixes #1024