我已经继承了一个Symfony项目(我实际上曾经工作过),需要重置密码才能登录到后端。失去的sfGuard管理员密码 - 需要重置
我有权访问MySQL数据库。我尝试了连接盐和新密码,然后用sha1(它似乎已经登录到数据库中的算法)对此进行哈希处理,但没有运气。
任何人都可以提供任何帮助,如何我可以更改密码而无需登录到Web应用程序?
谢谢,丰富。
我已经继承了一个Symfony项目(我实际上曾经工作过),需要重置密码才能登录到后端。失去的sfGuard管理员密码 - 需要重置
我有权访问MySQL数据库。我尝试了连接盐和新密码,然后用sha1(它似乎已经登录到数据库中的算法)对此进行哈希处理,但没有运气。
任何人都可以提供任何帮助,如何我可以更改密码而无需登录到Web应用程序?
谢谢,丰富。
您可以从代码更容易做到这一点..
$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());
我使用的是帕克的任务。
创建项目/ lib目录/任务文件并调用它setUserPasswordTask.class.php(名称必须与“任务”结尾)
类会是这个样子:
<?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());
}
}
?>
为你可以看到here
已经有可用的内部sfGuardPlugin一个任务,你可以在命令行推出
./symfony guard:change-password your_username new_password
这是sfGuardPlugin的最新版本中添加的吗?我在7月份发布的那个中看不到它今年。谢谢你指出的tho – SuitedSloth
也许它只在svn版本的插件中提供,并没有包含在zip/plugin中,我不知道我只使用svn。 – Pascal
我试过添加这个文件(它并不存在于我的版本中)使用juand的答案在下面,但是当在cli上运行任务时,我得到警告(未定义的索引argv和array_shift()期望参数1为数组,null给定)来自sfCommandM anager - 然后给我一个可用的symfony命令列表。 – Rich
谢谢! 我会给它一个去。在此之前,对数据库的任何帮助都会很好。 – Rich
要从数据库中改变它,你可以定义一个盐,比如说“123”,并用该值设置salt字段,然后计算123的sha1值加上你想要的密码。 “123password”。设置密码值为,你的密码现在是“密码” – SuitedSloth
你可以用它来计算SHA1值:http://hash.online-convert.com/sha1-generator – SuitedSloth