1

I am working on Login page "costume VF page" that will check the username and password in "User" standard object.

Is there anyway provided by salesforce to check the username and password then redirect the user to other page ?

I tried this and it works, but I wonder if there is a better way and in matter of fact I want to use sessions:

<apex:form >
  <apex:inputField value="{!user.Username}" label=""></apex:inputField>
  <apex:commandButton action="{!login}" value="Login" />
</apex:form>

-- Controller --

public PageReference login() {
    PageReference redirect;
    try{
       users = [Select u.Username From User u WHERE u.Username =: user.username ];
       if(users.isEmpty()){
          redirect = new PageReference('/apex/Login'); 
       }else{
          redirect = new PageReference('/apex/Index?username='+user.username); 
       }
       redirect.setRedirect(true); 
       }catch(Exception e){
          redirect = new PageReference('/apex/Login'); 
     }
     return redirect;
}
  • If this is for internal users, consider enabling "My Domain" and rebranding the login page instead. See the following videos youtube.com/watch?v=lIizBtQCGJ8 and youtube.com/watch?v=265HzJRgEcc – James Loghry Jan 22 '14 at 17:08
  • Is this for a Site page? I'm kind of presuming so, because if they were already logged in, they wouldn't need to log in again. In fact, this page wouldn't work outside the context of a Site, because they would have to log in before they could reach this page. – sfdcfox Jan 22 '14 at 17:43
  • @sfdcfox consider it outside the SF website, like a portal page. I don't know actually, but I should implement it as required. If you have any other way inlight me – Hasan Alkhatib Jan 23 '14 at 1:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.