首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >丢失sfGuard管理员密码-需要重置

丢失sfGuard管理员密码-需要重置
EN

Stack Overflow用户
提问于 2011-12-13 00:50:27
回答 2查看 5K关注 0票数 3

我继承了Symfony项目(我之前实际工作过),需要重置密码才能登录到后端。

我可以进入MySQL的数据库。我尝试过将salt和新密码连接起来,然后使用sha1 (它似乎已经记录在数据库中的算法)对其进行哈希处理,但没有成功。

有没有人可以帮助我在不登录web应用程序的情况下更改密码?

谢谢,瑞奇。

EN

回答 2

Stack Overflow用户

发布于 2011-12-13 01:02:21

如您所见,here

sfGuardPlugin中已有一个任务可用,您可以在cli中启动它

代码语言:javascript
复制
./symfony guard:change-password your_username new_password
票数 7
EN

Stack Overflow用户

发布于 2011-12-13 00:54:28

你可以从代码中更容易地做到这一点。

代码语言:javascript
复制
$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结尾)

这个类看起来像这样:

代码语言:javascript
复制
<?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() );


    }

}

?>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8477766

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档