Skip to content

Commit

Permalink
Add custom password validation example (#2250)
Browse files Browse the repository at this point in the history
  • Loading branch information
pwizla authored Oct 9, 2024
1 parent 2fa268b commit 654327d
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions docusaurus/docs/dev-docs/plugins/users-permissions.md
Original file line number Diff line number Diff line change
Expand Up @@ -1354,3 +1354,30 @@ If you need to configure a custom handler to accept other URLs, you can create a
},
},
```

### Creating a custom password validation

To add password validation at the API level, you can create a custom function passed to `validationRules` in the configuration of the Users & Permissions plugin, as in the following example:

```js title="/config/plugins.js|ts"
// ... other plugins configuration ...
// Users & Permissions configuration
'users-permissions': {
config: {
validationRules: {
validatePassword(value) {
if (value.length < 8) {
// custom error message
throw new Error('password should be more than 8 letters');
}

if (value.length > 24) {
// throws default error message
return false;
}

return true; // Validation passed
},
},
},
},

0 comments on commit 654327d

Please sign in to comment.