我继承了一个Symfony项目(我实际上在不久前工作过),需要重置密码才能登录到后端。
我可以访问MySQL数据库。我试过将盐和新密码连接起来,然后用sha1(似乎已经登录到DB的算法)对其进行哈希,但没有运气。
谁能提供任何帮助,我如何可以改变密码,而不登录到web应用程序?
谢谢,富有。
如你所见
有一个任务已经在sfGuardPlugin中可用,你可以在cli中启动
./symfony guard:change-password your_username new_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 change for user: ", $sf_guard_user->getUsername() );
我使用一个pake任务。
在project/lib/task中创建一个文件,命名为setUserPasswordTask.class.php(名称必须以" task "结尾)
这个类看起来像这样:
<?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() );
}
}
?>