我继承了Symfony项目(我之前实际工作过),需要重置密码才能登录到后端。
我可以进入MySQL的数据库。我尝试过将salt和新密码连接起来,然后使用sha1 (它似乎已经记录在数据库中的算法)对其进行哈希处理,但没有成功。
有没有人可以帮助我在不登录web应用程序的情况下更改密码?
谢谢,瑞奇。
发布于 2011-12-13 01:02:21
如您所见,here
sfGuardPlugin中已有一个任务可用,您可以在cli中启动它
./symfony guard:change-password your_username new_password发布于 2011-12-13 00:54:28
你可以从代码中更容易地做到这一点。
$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() );
}
}
?>https://stackoverflow.com/questions/8477766
复制相似问题