Reputation: 553
I've inherited a Symfony project (which I actually worked on a while ago) and need to reset the password to login to the back-end.
I have access to the MySQL database. I've tried concatenating the salt and new password, then hashing this with sha1 (the algorithm it seems to have logged in the DB), but with no luck.
Can anyone offer any assistance as to how I can change the password without logging into the web application?
Thanks, Rich.
Upvotes: 3
Views: 5166
Reputation: 1284
as you can see here
there is a task already available inside sfGuardPlugin that you can launch in cli
./symfony guard:change-password your_username new_password
Upvotes: 7
Reputation: 4716
You can do it from code more easily..
$sf_guard_user = sfGuardUserPeer::retrieveByUsername( 'USERNAME_HERE' );
if( is_null($sf_guard_user) ){
throw new \Exception( 'Could not find user' );
}
$sf_guard_user->setPassword( $password );
$sf_guard_user->save();
$this->logSection( "Password change for user: ", $sf_guard_user->getUsername() );
I use a pake task.
Create a file in project/lib/task and call it setUserPasswordTask.class.php (name must end in "Task")
The class would look something like this:
<?php
class setClientPasswordTask extends sfBaseTask {
/**
* @see sfTask
*/
protected function configure() {
parent::configure();
$this->addArguments(array(
new sfCommandArgument( 'username', sfCommandArgument::REQUIRED, 'Username of the user to change', null ),
new sfCommandArgument( 'password', sfCommandArgument::REQUIRED, 'Password to set', null )
));
$this->addOptions(array(
new sfCommandOption( 'application', null, sfCommandOption::PARAMETER_REQUIRED, 'The application name', 'frontend' ),
new sfCommandOption( 'env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'prod' ),
new sfCommandOption( 'connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'propel' ),
));
$this->namespace = 'guard';
$this->name = 'set-user-password';
$this->briefDescription = 'Changes a User\'s password.';
$this->detailedDescription = 'Changes a User\'s password.';
}
/**
* @see sfTask
*/
protected function execute( $arguments = array(), $options = array() ) {
// initialize the database connection
$databaseManager = new sfDatabaseManager( $this->configuration );
$connection = $databaseManager->getDatabase($options['connection'])->getConnection();
$configuration = ProjectConfiguration::getApplicationConfiguration( $options['application'], $options['env'], true );
sfContext::createInstance( $configuration );
// Change user password
$username = $arguments['username'];
$password = $arguments['password'];
$sf_guard_user = sfGuardUserPeer::retrieveByUsername( 'USERNAME_HERE' );
if( is_null($sf_guard_user) ){
throw new \Exception( 'Could not find user' );
}
$sf_guard_user->setPassword( $password );
$sf_guard_user->save();
$this->logSection( "Password changed for user: ", $sf_guard_user->getUsername() );
}
}
?>
Upvotes: 1