• #19740
    Salesforce | Saurabh Saurabh #255
    Forcetalks

    Can we generate the random string or random password using Apex?

    Can we generate the random string or random password using Apex?

     

    #19752
    Salesforce | Suraj Suraj #149
    Forcetalks

    Hi Saurabh,

    You can use this:

    Integer len = 10;
    Blob blobKey = crypto.generateAesKey(128);
    String key = EncodingUtil.convertToHex(blobKey);
    String pwd = key.substring(0,len);

    #35343
    Salesforce | Parul Parul #3
    Forcetalks

    Hi,

    public String testGenerate(Integer getLength)

    {
    String charString = ‘[email protected]#$%^&*()nopqrstuvwABCDPQRSTUVWXYZ0123456789abcdefghijkEFGHIJKLMNOlmxyz’;
    String randomNew = ”;
    while (randomNew .length() < getLength)

    {
    Integer changeInt = Math.mod(Math.abs(Crypto.getRandomInteger()), charString.length());
    randomNew += charString.substring(changeInt , changeInt +1);
    }
    return randomNew ;
    }

    Hope this helps.

Viewing 3 posts - 1 through 3 (of 3 total)

Please to reply to this topic.

CONTACT US

We're not around right now. But you can send us an email and we'll get back to you, asap.

Sending

About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2019 Forcetalks. All Right Reserved.

Log in with your credentials

or    

Forgot your details?