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
NasirNasir 

to create a portal with username and password

i have a object called member  in SF.In its page layout there are many fields and amoung those fields there is a field called "username "and "password".now i had created a record in that member object with "username =member1" and password='112345'.

 

Now i want to create a web site.from where  a member enter his user  enter the usename and password it should hit the date base and member could see his record and edit it also. i had created a vf page

 

<apex:page standardController="Member__c" extensions="members" showHeader="false">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection title="Login page">
Please enter user name and Password

<apex:inputField value="{!Member__c.User_Name__c}" /><br/>
<apex:inputField value="{!Member__c.Password__c}"/>

</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton action="{!login}" value="login"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
  
</apex:page>
public class members {
public string username {get; set;}
public string password {get; set;}
    public members(ApexPages.StandardController controller) {

    }
    public Pagereference login(){
    String startUrl = System.currentPageReference().getParameters().get('startURL');
        return Site.login(username, password, startUrl);
    
    }
    public members(){}
    public static testMethod void testmembers(){
    members mem = new members();
    mem.username = 'member1';
    mem.password = '12345';
    
    System.assertEquals(mem.login(),null); 
    
    }

}

but this code is not working.

Please help me out.

Pradeep_NavatarPradeep_Navatar

Try out the sample code given below :

 

      public members(ApexPages.StandardController controller)

      {

               this.member = (Member__c)stdController.getRecord();

               System.debug('%%%%%%%%%'   +   member.User_Name__c);

               System.debug('%%%%%%%%%'   +   member.Password__c);

               username = member.User_Name__c;

               password = member.Password__c;

       }

 

      You will be able to log in to the customer portal sucessfully.

 

Did this answer your question? if so, please mark it solved.