drny60365
drny60365
2014-08-26 15:09

too long

  • configure
  • yaml
  • database
  • php
已采纳

I would like to know if it's possible in symfony 1.4 to set the db connection password (and username) somewhere else, or if it's possible to encrypt this data somehow.

The client who asked for it said it results unsecure, so i'm looking for an alternative way to do this.

Thanks.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • duanshan3427 duanshan3427 7年前

    You can use php in yml files:

    all:
      doctrine:
        class: sfDoctrineDatabase
        param:
          dsn: '<?php echo DSN_CONSTANT ?>'
          username: '<?php echo $_ENV['DB_USERNAME'] ?>'
          password: '<?php echo $_ENV['DB_PASSWORD'] ?>'
    

    EDIT:

    The above way will store credentials on filesystem, in php files. If you want to prevent this, change the class to your own, extend it, and retrieve the credentials any other way you want, eg, enviroment variables:

    class MyDoctrineDatabase extends sfDoctrineDatabase {
      public function initialize($parameters = array())
      {
        $parameters['dsn'] = $_ENV['DSN'];
        $parameters['username'] = $_ENV['DB_USERNAME'];
        $parameters['password'] = $_ENV['DB_PASSWORD'];
        return parent::initialize($parameters);
      }
    }
    
    点赞 评论 复制链接分享

为你推荐