Question

Not a SFDC expert but need to integrate a web form hosted in SFDC. For other reasons, this page needs to capture an initial password and send off the salted/sha256'd version of the password to another system or a human. I don't want to save the cleartext obviously.

What's the lightest touch way to hash the password before saving? I could do this in the browser except that I don't want to rely on Javascript.

Was it helpful?

Solution

Apex has a Crypto class which has a generateDigest method you need, something like:

Blob hash = Crypto.generateDigest('SHA-256', Blob.valueOf(passwordString));

OTHER TIPS

Yes, you should add this code to an apex trigger.

trigger on sObject(before insert){
  for(sObject s: trigger.new){
    s.Hash__c = Crypto.generateDigest('SHA-256', Blob.valueOf(s.passwordString__c));
    s.passwordString__c = null;
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top