function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
RockersRockers 

How to customize the functionality of change password provided by the Salesforce?

Hi Friends,

 

              We just developed one site for my client requirement. In that, we are using the standard functionalities of forgot password and change password functionalities. Now, the requirement is that we need to customize the functionality of change password. That means, we need to provide the facility for the user to change the password any time. we provide the link for change password.

 

            when the user clicks on that link, he redirects to the change password page. But, in the page, only two options are available. Those are, "New Password" and "Verify New Password". We are not able to view the input field of "Old Password".

 

            But, when the user clicks on forgot password, then one email sent to his account with temp password. this is the standard functionality done by Salesforce itself. Then, when user login with that temp password, then the user re-directs to the change password, then only, those three fields are visible on the page. 

 

           Now, the functionality of the change password need to be implemented with out the option of forgot password. The user can change his password any time.

 

           So, now my query is how to implement the functionality of change password which happens with the forgot password functionality, need to implement with out that option.

 

            Pls suggest me how to implement this.

 

Regards,

Phanikumar

IspitaIspita

Hi,

The functionality of change password can be customized or modified by extending/ customizing the "Site Class"

 

Refer to the following link for more on this:-

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_sites.htm

 

Code using "SiteControllerClass"


/**
 * An Apex class that creates a portal user
 */ 
    
public class SiteRegisterController {
    // PORTAL_ACCOUNT_ID is the account on which the contact will be created on  
    
    //  and then enabled as a portal user. 
    
    //Enter the account ID in place of <portal_account_id> below. 
    
    private static Id PORTAL_ACCOUNT_ID = '<portal_account_id>';
    
    public SiteRegisterController () {
    }

    public String username {get; set;}
    public String email {get; set;}
    public String password {get; set {password = value == null ? value : value.trim(); } }
    public String confirmPassword {get; set { confirmPassword = 
        value == null ? value : value.trim(); } }
    public String communityNickname {get; set { communityNickname = \
        value == null ? value : value.trim(); } }
      
    private boolean isValidPassword() {
        return password == confirmPassword;
    }
    
    public PageReference registerUser() {
        // If password is null, a random password is sent to the user 
    
        if (!isValidPassword()) {
           ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR, 
               Label.site.passwords_dont_match);
           ApexPages.addMessage(msg);
            return null;
        }    
        User u = new User();
        u.Username = username;
        u.Email = email;
        u.CommunityNickname = communityNickname;
        
        String accountId = PORTAL_ACCOUNT_ID;

        // lastName is a required field on user, but if it isn't specified,  
    
           the code uses the username
        String userId = Site.createPortalUser(u, accountId, password);
        if (userId != null) { 
            if (password != null && password.length() > 1) {
                return Site.login(username, password, null);
            }
            else {
                PageReference page = System.Page.SiteRegisterConfirm;
                page.setRedirect(true);
                return page;
            }
        }
        return null;
    }
    // Test method for verifying the positive test case 
    
    static testMethod void testRegistration() {
        SiteRegisterController controller = new SiteRegisterController();
        controller.username = 'test@force.com';
        controller.email = 'test@force.com';
        controller.communityNickname = 'test';
        // registerUser always returns null when the page isn't accessed as a guest user 
    
        System.assert(controller.registerUser() == null);
        controller.password = 'abcd1234';
        controller.confirmPassword = 'abcd123';
        System.assert(controller.registerUser() == null);
    }

}

 

 

The following is the Visualforce registration page that uses the SiteRegisterController Apex controller above:

<apex:page id="Registration" showHeader="false" controller="SiteRegisterController" standardStylesheets="true"> 
  <apex:outputText value="Registration"/>
  <br/>
  <apex:form id="theForm">
    <apex:messages id="msg" styleClass="errorMsg" layout="table" style="margin-top:1em;"/>
    <apex:panelGrid columns="2" style="margin-top:1em;">
      <apex:outputLabel value="{!$Label.site.username}" for="username"/>
      <apex:inputText required="true" id="username" value="{!username}"/>
      <apex:outputLabel value="{!$Label.site.community_nickname}" for="communityNickname"/>
      <apex:inputText required="true" id="communityNickname" required="true" value="{!communityNickname}"/>
      <apex:outputLabel value="{!$Label.site.email}" for="email"/>
      <apex:inputText required="true" id="email" required="true" value="{!email}"/>
      <apex:outputLabel value="{!$Label.site.password}" for="password"/>
      <apex:inputSecret id="password" value="{!password}"/>
      <apex:outputLabel value="{!$Label.site.confirm_password}" for="confirmPassword"/>
      <apex:inputSecret id="confirmPassword" value="{!confirmPassword}"/>
      <apex:outputText value=""/>
      <apex:commandButton action="{!registerUser}" value="{!$Label.site.submit}" id="submit"/>
    </apex:panelGrid>
  </apex:form>
cod</apex:page>

 Hope this gives you a clue....

RockersRockers

Hi Ispita,

 

       Thanks for your reply.

 

        Can we capture the login credentials of the logged user.

 

Regards,

Phanikumar