0

I am working on a project to send custom WelcomeEmail to 400 new users in Salesforce, since Salesforce cannot send the verified email when creating users through data loader. (I don't prefer to send "ResetPassword" email to user as well, cuz it's not NewUsers friendly.)

**WelcomeEmail target functions:**
 1. Appropriate Login Instructions
 2. Include a Link that User can Set Password

I've developed an automated process to streamline this task. However, I'm facing a security problem, and I would appreciate your insights or suggestions for improvement.


Here's an overview of my current process:

Settings:

  1. Create NeedSetPW__c: New checkbox field on User Object
  2. Create SendCustomEmail__c: New checkbox field on User Object
  3. Create Apex Trigger:
trigger TestSetPassword on User (after update) {
  for(User u : Trigger.new){
    if(u.IsActive == true && u.NeedSetPW__c == true && u.SendCustomEmail__c == false){
       system.setPassword(u.Id, 'Aa1234567s');
       system.debug(u.id);
      }
     }
    }
  1. Create AutoLaunched Flow: https://i.sstatic.net/kMrp2.jpg
  2. Create Lightning Email Template

Here's the Steps

  1. Admins batch insert 400 users as inactive.
  2. Admins then update the users to active status and set NeedSetPW=true.
  3. An Apex trigger sets a predefined password when [IsActive==true && NeedSetPW__c==true && SendCustomEmail__c==false] .
  4. Admins batch update SendCustomEmail__c=true to trigger a flow.
  5. A Flow sends out an email when [IsActive==true && SendCustomEmail__c=true], and then resets NeedSetPW__c and SendCustomEmail__c to false.
  6. This process successfully sends out a welcome email with login instructions, and user will redirect to change password screen when using the predefined password to login.

The process uses fixed password for all new users, which is a security concern. Moreover, due to the limitations of Salesforce Lightning email templates, I can't include dynamically generated passwords in the email.

I'm considering ways to improve this process, especially in terms of security while maintaining a good user experience. Are there best practices or alternative approaches I should consider?

Thank you in advance for your valuable suggestions!

7
  • In security terms, you're reinventing the wheel of Reset Password. Not friendly to new users? Sure but it's far more risky to your organization to send passwords in plaintext over email.
    – identigral
    Commented Dec 2, 2023 at 17:36
  • @identigral Thanks for your comments! I'm curious about what risks you imagine there might be? A user who has not logged in before will be redirect to change password screen when he uses predefined password to log in, just like clicking the reset password link.
    – YHsuan
    Commented Dec 3, 2023 at 5:37
  • Plaintext password can be easily exfiltrated from the email - it passes through many systems before landing in recipient's mailbox. Reset Password link is one-time use only and it expires. From an end-user experience perspective, going through a change password screen upon first login is very similar to Reset Password.
    – identigral
    Commented Dec 3, 2023 at 11:30
  • I don't suppose using SSO/SAML at your company is an option? Then you don't have to worry about passwords at all
    – cropredy
    Commented Dec 3, 2023 at 21:32
  • @identigral Got it, I will find a new way. Thank you!
    – YHsuan
    Commented Dec 4, 2023 at 5:15

1 Answer 1

0

here is one way so that you can send separate password for each users:

  1. Create a new field Temporary Password on User object.
  2. From the step 3 mentioned in the problem statement, populate this field after generating a new password.
  3. In the welcome email template insert this field value to show.

Now to generate the password, you have to setup some way as per your creativity! few suggestions a few ways

  1. like manipulating and using user Id or substring of user Id as password
  2. Add current count of some object records to user Id
  3. Add a invocable apex to create a set of random number using Math. random() function.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .