Wednesday, 23 October 2013

Reset Password code in VF and Apex

Visual Force Code:

<apex:page controller="Reset">
  <center>
   <apex:form >
   <apex:messages />
    <apex:pageBlock title="Reset Password">
     <b>Reset Your Password</b><br/>&nbsp;
      <apex:panelGrid columns="2">
       Enter Email <apex:inputText value="{!email}"/>
       Enter Password <apex:inputsecret value="{!pass}"/>
       Conform Password <apex:inputsecret value="{!conf_pass}"/>
      </apex:panelGrid>
     <apex:commandButton value="Check In" action="{!Save}"/>
    </apex:pageBlock>
   </apex:form>
  </center>
</apex:page>

Apex Code:

public with sharing class Reset {
    public String conf_pass { get; set; }
    public String pass { get; set; }
    public String email { get; set; }
    list<Registration__c> reg_obj;
    //string email;
    string name;
    string password;
    
    public reset(){
        reg_obj = [select id,Email__c,First_Name__c,Password__c from Registration__c];
    }
    
    public PageReference Save() {
    
        if(pass == conf_pass){
            for(Registration__c reg : reg_obj){
                if(reg.Email__c == email){
                    reg.Password__c = pass;
                    update reg;
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, 'Your Password is update now.'));                
                }
            }
        }else{
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, 'Sorry your password and confirm password are not match'));                
        }
          return null;
    }

}

No comments:

Post a Comment