I would know if there is an Apex method to validate a Password during the creation of a new User in Apex.

I found the method Site.validatePassword(user, password, confirmpassword) but it's available only during the self-registration for a community.

In my case, I'm exposing an Apex REST WS to create a new User and I would check if the password is correct or not in order to complete the process and create the User.

  • When you say password is correct or not, what are you referring to? How does your API receive the password? What do you want to check here? – Jayant Das Apr 26 at 14:07
  • 1
    You don't set the password until after user creation. – Adrian Larson Apr 26 at 14:20
  • @JayantDas I'm exposing an Apex REST WS, I receive some parameters (firstname, lastname, password, email) and in my code I create the User. I'm implementing a validation on those parameters and for the password I want check if it fullfils my Password Policies (for example, Minimum password length) – vt89 Apr 26 at 14:31
  • @AdrianLarson Yes, it's right. I create the user record and then I invoke the method System.setPassword(userID, newPassword) but I would check if the password fulfills my Password Policies otherwise I don't create the User and return an error. – vt89 Apr 26 at 14:35
  • I believe calling setPassword should fail if the value doesn't meet your policies. Have you tried it? What behavior do you observe? I personally haven't, it's just my assumption. – Adrian Larson Apr 26 at 14:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.