I’m trying to use the package ‘joi-password-complexity’ to validate password in users.js for the vidly app. It’s not working. I tried some solutions but without success. There is no much documentation on how to use it with an old version of Joi.

I’d like to know if is there someone that has already successfully tried to use it. TIA

here is my validateUser function in the module vidly\models\user.js:

function validateUser(user) {
   const schema = {
      name: Joi.string().min(5).max(50).required(),
      email: Joi.string().min(5).max(255).required().email(),
      password: passwordComplexity().required()
   return Joi.validate(user, schema);

By digging through his code for an hour, I figured out that the author didn’t export the extension correctly. See source (line 114)

However, you can still do this:

const method = (value, helpers) => {
    const { error } = passwordComplexity().validate(value);
    const errors = helpers.errorsArray();
    error?.details.forEach(err => errors.push(helpers.error(err.type)));
    return error ? errors : value;

So that you can do-

const schema = { 
    name: ...
    email: ...
    password: Joi.string().custom(method, 'Password Complexity').required()


Joi.string().custom(method, 'Password Complexity').validate(...);

By the way, that fella writes shit codes and my day is ruined x(.

Thank you for your reply.
But I don’t agree with you: I don’t think that some code is bad only because I don’t know how to use it correctly :slight_smile:

If you look in ‘node_modules\joi-password-complexity’ you can see the actual code in use. Moreover in are specified the Requirements :slight_smile: So it’s likely that this is not working only because I’m using an old version of Joi. When I will finish my course I will come back and update Joi. For the moment I thank you for you effort. sorry if I caused you a bad moment :wink:

1 Like

The code exported the extension wrapped in a function that can be used in the way the read-me file shows. It supposed to export the extension and extend the Joi class.

And I installed the newest version of Joi and I also failed to use it as an extension, so it’s not the matter of Joi version.

And don’t worry, I’m just joking with memes. “and my day is ruined” is a meme phrase and I’m always happy to help people with questions ;).

1 Like

Ok :slight_smile: thank you for your precisation. thank you for your addon.
For now I will freeze it in a vault. Otherwise I am going to lose other time struggling with it an entire day :joy:
If I solve it I will update this post.

By the way if you search on the web, there was an answer in the old forum but Mosh staff didn’t save the old forum :sob: :sob: :sob:
and so all those precious information were lost :worried:
I also searched in web-archive but no trace at all of that, last and unique saving was in August.

@annadema google results have a small down arrow ▼in the URL above the title. If you click it you can get the page from google’s cache.

1 Like

Wow :astonished:. Great discover!! Thank you very much
Even if for this specific problem there are not any other solutions that I have not already tried :frowning:
It will be useful for other issues.
I’m downloading and saving for future all the old pages of the forum cached in Google Search :+1: :+1: :+1:

:+1: If you find anything especially valuable feel free to repost it here in the respective category.

Since you are processing all post maybe you will find out what the FAQ are and repost them with the best answers? That may help new users and can be a good starting point for sticky or wiki posts as soon as anyone of us gains the privileges to make posts sticky or wiki posts.

It could be a good idea.
I’d like to give my contribute to the community sharing those info but it would be a time-wasting activity without a specific request. And I don’t like post something that I didn’t checked before

If I experienced some issue that I can solve only in the old forum pages , then I will certainly post the solution here :slight_smile:

For your other request, sadly I haven’t find yet any old page with the FAQ list.

My code didn’t work because I didn’t install the right version of joi-password-complexity

With the version available at the time of recording video (with all the requirements currently installed on my environment, the same of the course) the package “Joi-password-complexity” can be used as in the following code.

First I installed
npm i joi-password-complexity@2.0.1

In the user module on the top I imported the package:
const passwordComplexity = require("joi-password-complexity");

Then the validateUser simply becomes :

 function validateUser(user) {
    const schema = Joi.object({
        name: Joi.string().min(5).max(50).required(),
        email: Joi.string().min(5).max(255).required().email(),
        // password: Joi.string().min(5).max(255).required()
        password: new passwordComplexity(),
    return Joi.validate(user, schema);

A valid password could be for example: “A234567!”
with the default complexityOptions