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
AuraDevAuraDev 

Login Script

Hi Guys, I need to write a PHP script and dont want to start from scratch.

What I'm looking for is a script that takes a username and password (that is entered on a form), and checks to see if that user/pass exists in our SalesForce customer database, but also checks a third field which defines whether or not they are a subscriber.

So:

<Connect to salesforce>

<Select Customer where user = x>
    If {user doesnt exist -> return to login and show error: user does not exist}
    If {user.pass doesnt = y -> return to login and show error: invalid password}
   
// Check subscription status
    If {customer.subscription_status = inactive -> return to login and show error: Subscription Inactive}

else { Set session var for username and log the customer into the website}


Anyone have something like this sitting around?

Thanks,
Chris
Alex 2.0Alex 2.0
here's a sample piece of code that will get you started. You will have to code the rest yourself :smileywink:


require_once ('SforcePartnerClient.php');
require_once ('SforceHeaderOptions.php');

$mySforceConnection = new SforcePartnerClient();
$mySforceConnection->createConnection('path/to/partner.wsdl.xml');
$loginResult = $mySforceConnection->login("username", "password");
$queryResult = $sfdc->query("select Id from contact where email='$user_email' and Password__c='$user_password' ands third_field__c='$somevalue'");
if($queryResult->records[0]->Id[0]){
 //logged in!
}
else{
 //login failed!
}