3

私は Symfony プロジェクト (実際に少し前に取り組んだプロジェクト) を継承しており、バックエンドにログインするためにパスワードをリセットする必要があります。

MySQL データベースにアクセスできます。ソルトと新しいパスワードを連結してから、これをsha1(DBにログインしているように見えるアルゴリズム)でハッシュしようとしましたが、うまくいきませんでした。

Web アプリケーションにログインせずにパスワードを変更する方法について、誰か助けてもらえますか?

ありがとう、リッチ。

4

2 に答える 2

7

ここでわかるように

cli で起動できる sfGuardPlugin 内で既に利用可能なタスクがあります

./symfony guard:change-password your_username new_password
于 2011-12-12T17:02:20.550 に答える
1

コードからより簡単に実行できます..

$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() );

私はパケタスクを使用しています。

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() );


    }

}

?>
于 2011-12-12T16:54:27.710 に答える