Auto generate password apex salesforce.

To generate random password you can use crypto class for generating password in apex.

crypto class will generate random blob. Use can use that blob for creating String.
use trim string to whatever length.

Here is Sample class for generating password:

public class PasswordGenerator {
public static String getPassword(Integer passlength) {
Blob blobKey = crypto.generateAesKey(128); String key = EncodingUtil.convertToHex(blobKey); System.debug(key);
return key.substring(0,passlength); } }

No comments:

Post a Comment