Wednesday, 23 October 2013

Login Page Using Salesforce Code

Program for Login Page Using Salesforce with VisualForce and APEX Code :

Visual force  Code:

<apex:page controller="LoginPage" showHeader="false" sidebar="false"  standardStylesheets="true">
<body background="{!$Resource.pic}" width="150" height="150"/>
<apex:form >
<center>
<b>Login Page</b>
<apex:panelGrid columns="2" style="margin-top:2em;">
<b>UserName</b>
<apex:inputText required="true" id="username" value="{!username}"/>
<b>Password</b>
<apex:inputSecret id="password" value="{!password}"/>
<b><apex:messages /></b>
</apex:panelGrid>
<apex:commandButton action="{!loginUser}" value="Login" id="save"/>
<apex:commandButton action="{!Cancel}" value="Cancel" id="cancel"/><br/><br/>
<apex:commandLink action="{!registerUser}" value="Register" id="register"
      immediate="true"/><br/> &nbsp; <br/>
<apex:commandLink action="{!ForgotPassword}" value="Forgot Password"
      id="ForgotPassword"  immediate="true"/>
</center>
</apex:form>
</apex:page>


Apex Code :

public class LoginPage {
    public PageReference ForgotPassword() {
        return page.ForgotPassword;
 }
 public PageReference Cancel() {
    PageReference newPage2 = new PageReference('/apex/login');
        newPage2.setRedirect(true);
        return newPage2;
 }
 public PageReference loginUser() { 
     try{
     List<Registration__c> log=[select Email__c,password__C from Registration__c];
       for(Registration__c obj:log){
       if(obj.Email__c==username && obj.password__c==password){
       //PageReference newPage1 = new PageReference('/apex/new');
       // newPage1.setRedirect(true);
        return page.new;
       }
       }
     }
     catch(Exception E){  
     return null;
     }
 apexPages.addMessage(new ApexPages.message(ApexPages.severity.Error,'.Invalid
         Username or Password'));
     return null;
}      
public String password { get; set; }
public String username { get; set; }
public PageReference registerUser() {
PageReference newPage = new PageReference('/apex/reg');
newPage.setRedirect(true);
return newPage;
}
}

No comments:

Post a Comment