JavaScript Personalize password validation function used by accounts-ui custom password validation in angular 7,custom password validation in

Meteor accounts uses the following function to validate password format:

validatePassword = function (password) {
  if (password.length >= 6) {
    return true;
  } else {
    loginButtonsSession.errorMessage("Password must be at least 6 characters long");
    return false;
  }
};

Is it possible to overwrite this function? If so, how?

Answer:1

According to the docs Meteor does not send the password in clear through the wire. That's why you can't check the password on the server easily.

You could do one of the following though:

  • Create user via custom meteor method

    You could build a custom login form which calls a Meteor.method which is defined on the server. In this meteor method call Account.createUser().

    example code (untested):

Meteor.methods({
  createUser: function(email, password) {
    if (password.length < 5) {
      throw new Meteor.Error('password-too-short', 'Use longer password');
    }
    Accounts.createUser({email: email, password: password});
  }
});
Meteor.call('createUser', email, password);

Warning: The password is sent in clear text to the server. Make sure to do have your DDP connection secured with SSL.

  • Check password on the client

    Sure - you should never trust the client - but it's not very likely that a user modifies client side JavaScript code just to be able to set an easier password.

Answer:2

Depends on the framework you are using. But ideally, you could use a regex and validate on both the front end and back end. For example:

if (Meteor.isClient) {
  Template.register.events({
    'submit form#password-form': function (e, template) {
      let pass = $(e.target).find('input[type="password"]');
      let passwordRegex = /\w{4,20}/gi   // this is just an example
      if (!passwordRegex.test(pass)) {
        // update dom as needed
      } else {
        Meteor.call('registerUser', $(e).serialize(), function (err, done) {
          if (!err) {
            // update for success
          } else {
            // update for failure
          }
        })
      }
    }
  });
} else {
  Meteor.methods({
    'registerUser': function (formObj) {
      check (formObj.password, String); // do all the checks first
      if (!/\w{4,20}/gi.test(formObj.password)) {
        throw new Meteor.Error(401, "Invalid password");
      }
    }
  });
}
Answer:3

A function whose declared type is neither 'void' nor 'any' must return a value. I have a createOrder function, that is supposed to return a promise. I have database calls in the function, and I'd ...

A function whose declared type is neither 'void' nor 'any' must return a value. I have a createOrder function, that is supposed to return a promise. I have database calls in the function, and I'd ...

I'm trying to split text the following like on spaces: var line = "Text (what is)|what's a story|fable called|named|about {Search}|{Title}" but I want it to ignore the spaces within parentheses. ...

I'm trying to split text the following like on spaces: var line = "Text (what is)|what's a story|fable called|named|about {Search}|{Title}" but I want it to ignore the spaces within parentheses. ...

  1. split string spaces java
  2. split string spaces python
  3. split string spaces c++
  4. split string spaces javascript
  5. split string spaces php
  6. split string spaces regex
  7. split string without spaces python
  8. split string without spaces into words java
  9. split string without spaces java
  10. split string multiple spaces python
  11. split string without spaces javascript
  12. split string by spaces python 3
  13. split string by spaces golang
  14. java split string spaces into array
  15. powershell split string spaces
  16. split string multiple spaces java
  17. split string by spaces matlab
  18. split string by spaces sql

I have a template Hello, ${user.name} stored in a variable. I am reading this from an external file using fs.read. Now, obviously when I attach to the innerHTML of a target div, it shows the string ...

I have a template Hello, ${user.name} stored in a variable. I am reading this from an external file using fs.read. Now, obviously when I attach to the innerHTML of a target div, it shows the string ...

I have a search form(search form) rendered inside a modal window(angular ui bootstrap modal). The input fields hold values that update my ng-model on submit. <script type="text/ng-template" id="...

I have a search form(search form) rendered inside a modal window(angular ui bootstrap modal). The input fields hold values that update my ng-model on submit. <script type="text/ng-template" id="...

  1. angular canactivate
  2. angular can't resolve all parameters
  3. angular cannot find module
  4. angular cannot read property of undefined
  5. angular candeactivate
  6. angular cannot get /
  7. angular canvas
  8. angular cancel http request
  9. angular cannot match any routes
  10. angular cannot find control with name
  11. angular canactivate redirect
  12. angular cannot find name 'require'
  13. angular cannot determine the module for class
  14. angular canload
  15. angular cannot access before initialization
  16. angular canactivatechild
  17. angular candeactivate example
  18. angular cannot set property of undefined
  19. angular cannot find control with path
  20. angular cannot read property of null