You need to sign in to do that
Don't have an account?

custom login page using vf and apex
hi i created one object called registration in that i have name, email,username,password i created one registration vf page with name, email,username,password and with save button when i click on save button its saveing in database. then i created one login vfpage in that i have username and password and login button once i click on login button need to compare username password with registered username password if match need show another page please help any one with this
If you register successful then you get the creddential for the same .
If credential are match then set cookies and redirect to other page and valiate the cookies in page action method.
If you are able to maintains the session for your application. for more felexible you used the wizard for the same
Thanks
Satya
--------------------------------------------
<apex:page standardController="gmailuser__c" extensions="gmailregcon">
<apex:form >
<apex:pageMessage severity="error" strength="2" summary="Error:" detail="{!errorMessage}" rendered="{!errorMessage != null}"/>
<apex:pageBlock title="Gmail Registration">
<apex:pageBlockSection >
<table>
<tr>
<td>
<apex:inputField value="{!reg.Name__c}" />
</td>
</tr>
<tr>
<td>
<apex:inputField value="{!reg.Email__c}"/>
</td>
</tr>
<tr>
<td>
<apex:inputField value="{!reg.UserName__c}"/>
</td>
</tr>
<tr>
<td>
<apex:inputSecret value="{!reg.Password__c}" id="password" />
</td>
</tr>
<tr>
<td>
<apex:commandButton value="Register" action="{!save}" />
</td>
</tr>
</table>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
registration controller
--------------------------------------------
public with sharing class gmailregcon {
public gmailuser__c reg { set; get;}
public List<gmailuser__c> gmailuserlist;
public transient String errorMessage { get; set; }
public gmailregcon(ApexPages.StandardController controller)
{
reg =(gmailuser__c)controller.getRecord();
}
public PageReference save()
{
gmailuser__c gu=new gmailuser__c();
try
{
gmailuserlist =[ select UserName__c from gmailuser__c where UserName__c=:reg.UserName__c];
if(reg!=null)
{
if(gmailuserlist.size()==0)
{
gu.Name__c=reg.Name__c;
gu.Email__c=reg.Email__c;
gu.UserName__c=reg.UserName__c;
gu.Password__c=reg.Password__c;
insert gu;
PageReference newPage = new PageReference('/apex/gmailloginp');
newPage.setRedirect(true);
return newpage;
}
else
{
errorMessage = 'Duplicate Username please try with another One';
}
}
}
catch(Exception e)
{
}
return null;
}
}
-------------------Apex Class-----------------
Public with sharing class TimeCardController{
public gmailuser__c reg { set; get;}
public List<gmailuser__c> gmailuser{get; set;}
public String passcode{get; set;}
public Boolean Match{get; set;}
public Boolean NoMatch{get; set;}
Public TimeCardController(){
reg = new gmailuser__c();
}
Public PageReference timecardsignin(){
gmailuser =new List<gmailuser__c>();
Match=false;
NoMatch=false;
gmailuser=[select UserName__c, Password__c from gmailuser__c where UserName__c =:reg.UserName__c AND Password__c =:reg.Password__c limit 1];
if(gmailuser.size()>0)
{
Match=true;
}
else
{
NoMatch=true;
}
PageReference pageRef = new PageReference('--Apex Page--');
pageRef.setRedirect(true);
return pageRef;
}
public PageReference doCancel()
{
PageReference pageRef = new PageReference('--Apex Page--');
pageRef.setRedirect(true);
return pageRef;
}
}
------------------Visualforce Page----------------
<apex:page Controller="TimeCardController">
<apex:form >
<apex:pageMessages />
<apex:pageBlock>
<apex:pageBlockSection columns="1">
<apex:pageBlockSectionItem">
<apex:outputLabel value="User Name" for="resource"/>
<apex:inputField value="{!reg.UserName__c}" id="resource"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem>
<apex:outputLabel value="Passcode" for="passcode" />
<apex:inputSecret value="{!reg.Password__c}" id="passcode"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem rendered="{!NoMatch}">Invalid Resource or Passcode</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Login" action="{!timecardsignin}"/>
<apex:commandButton action="{!doCancel}" value="Cancel"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
Make changes according to you if there is any mistake.. but it'll work.. and in pagereference write name of page on which you want to redirect after successful login..
Thanks for reply in above code its not checking username and password in database if am wrong username password and click on login button directly its going to another page with out giveing error message invalid username password......
i tryed finnaly i got bellow is my code..................... its working perfectly
login page
-------------------------------------------
<apex:page standardController="gmailuser__c" extensions="gmailloginpcon1">
<apex:form >
<apex:pageMessage severity="error" strength="2" summary="Error:" detail="{!errorMessage}" rendered="{!errorMessage != null}"/>
<apex:pageMessages id="shwmsg"></apex:pageMessages>
<h5><font size='4'>Congratulations Login here to check your data</font></h5>
<apex:pageBlock >
<apex:pageBlockSection >
<table>
<tr>
<td>
<apex:outputLabel value="Username"></apex:outputLabel>
<apex:inputText value="{!username}" />
</td>
</tr>
<tr>
<td>
<apex:outputLabel value="Password"></apex:outputLabel>
</td>
<td><apex:inputSecret value="{!password}" /></td>
</tr>
<tr>
<td>
<apex:commandButton value="Login" action="{!Verifyuser}" rerender="shwmsg"/>
</td>
</tr>
</table>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
-------------------------------------------
login controler
---------------------------------------------
public class gmailloginpcon1
{
public String password{ get; set; }
public String username{ get; set; }
public gmailuser__c reg { set; get;}
public transient String errorMessage { get; set; }
public List<gmailuser__c> gmailuserlist;
public gmailloginpcon1(ApexPages.StandardController controller)
{
reg =(gmailuser__c)controller.getRecord();
}
public PageReference Verifyuser()
{
try
{
List<gmailuser__c> yp = new List<gmailuser__c>();
system.debug('usernamemmmmmmmm'+username);
if(!String.isBlank(username))
{
yp = [SELECT username__c,password__c FROM gmailuser__c WHERE username__c =:username LIMIT 1];
if(yp.size()>0)
{
system.debug('yp[0].username__c value'+yp[0].username__c);
if(username == yp[0].username__c && password == yp[0].password__c)
{
PageReference newPage = new PageReference('/apex/welcome');
newPage.setRedirect(true);
return newpage;
}
}
else
{
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Invalid username and password please check'));
}
}
else
{
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Please enter username and password'));
}
}
catch(Exception e)
{
}
return null;
}
}
Just try it..
--------------------Apex Class-------------------
Public class gmController{
public NKBIT__Gmail__c reg { set; get;}
public List<NKBIT__Gmail__c> gmailuser{get; set;}
public Boolean Match{get; set;}
public Boolean NoMatch{get; set;}
Public gmController(){
reg = new NKBIT__Gmail__c();
}
Public PageReference timecardsignin(){
gmailuser =new List<NKBIT__Gmail__c>();
Match=false;
NoMatch=false;
gmailuser=[select NKBIT__User_Name__c, NKBIT__Password__c from NKBIT__Gmail__c where NKBIT__User_Name__c =:reg.NKBIT__User_Name__c AND NKBIT__Password__c =:reg.NKBIT__Password__c];
if(gmailuser.size()>0)
{
Match=true;
}
else
{
NoMatch=true;
}
PageReference pageRef = new PageReference('/apex/timecardpage');
pageRef.setRedirect(true);
return pageRef;
}
public PageReference doCancel()
{
PageReference pageRef = new PageReference('/apex/timecardpage');
pageRef.setRedirect(true);
return pageRef;
}
}
----------visualforce Page-----------------
<apex:page Controller="gmController">
<apex:form >
<apex:pageMessages />
<apex:pageBlock >
<apex:pageBlockSection columns="1">
<apex:pageBlockSectionItem >
<apex:outputLabel value="User Name" for="resource"/>
<apex:inputField value="{!reg.User_Name__c}" id="resource"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Passcode" for="passcode" />
<apex:inputSecret value="{!reg.Password__c}" id="passcode"/>
</apex:pageBlockSectionItem>
<apex:outputPanel id="notmatch">
<apex:pageBlockSectionItem rendered="{!NoMatch}">Invalid Resource or Passcode</apex:pageBlockSectionItem>
</apex:outputPanel>
</apex:pageBlockSection>
<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Login" action="{!timecardsignin}" reRender="notmatch"/>
<apex:commandButton action="{!doCancel}" value="Cancel"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>