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
gilagrigilagri 

Set Self Service User Password

How can I set a password on a self service user using PHP?

I found an example in asp.net, so I know it can be done in PHP:

Thanks for any help in advanced!
Park Walker (TAGL)Park Walker (TAGL)
Here is the code I use to generate a new password for a self-service user. You will not be able to use the code as is but it should give you what you need to accomplish the task.


private function resetPassword($username) {
$sfconn = new Sforce_Connection();
try {
$qry = "Select Id, ContactId from SelfServiceUser Where Username = '$username'";
$response = $sfconn->query($qry);
} catch (Exception $e) {
return "We are unable to locate that user name.";
}
if (count($response) > 0) { // there can be more than one, but only one should have a ContactId
$ssid = null;
foreach($response as $rec) {
if ( !is_null($rec->ContactId)) {
$ssid = $rec->Id;
break;
}
}
if (! is_null($ssid)) {
$ssuser = $sfconn->retrieve($ssid,'SelfServiceUser');
$success = $ssuser->resetPassword();
if ($success) {
$result = "You’re password has been reset. You should receive your new password shortly via email.";
Zend_Log::log(date('c').": PORTAL: Password reset for $username", Zend_Log::LEVEL_INFO );
} else {
$result = "We were not able to reset you’re password Please contact Centive support for urther assistance.";
Zend_Log::log(date('c').": PORTAL: Password reset failed for $username", Zend_Log::LEVEL_WARNING );
}
} else {
Zend_Log::log(date('c').": PORTAL: Could not find Contact for SS user $username", Zend_Log::LEVEL_ERROR );
$result = "There was a problem retrieving your user information. Please contact Centive support.";
}
} else {
$result = "We are unable to locate that user name.";
}
return $result;
}


Park
EricVlachEricVlach
use the setPassword() function. You need to know the self service user ID, which is different than the contact ID.

do a query for the self service user id, then use setPassword('userID' => ssuID, 'password' => password)

this will set the password without notifying the ss user.
JamesWJamesW

Does anyone know the syntax that I can use to set the password from Eclipse Anonymously Execute Code section? I periodically need to set batches of self service portal passwords and it would be great if I could do it form Eclipse rather than using C#.

 

Thanks in advance,

 

James