douzheng5717 2018-06-16 22:14
浏览 136
已采纳

使用相同的用户名/密码将所有用户插入到mysql数据库中是不安全的吗?

Sorry if this question is dumb. I'm kinda new to PHP/mySql...

I'm trying to set up a submissions form with no login necessary. I have a database in the server with one user with privileged access to it. So whenever people submit the form they can insert into the database using the same username/password...

My config file is like this for all users...

<?php

return [
    'database' => [
        'name' => 'database',
        'username' => 'myusername',
        'password' => 'mypassword',
        'connection' => 'host',
        'options' => [
            PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
         ]
    ]
];

Is this a standard/appropriate way to do it, or do I need to connect each user to the database through their own username/password?

  • 写回答

2条回答 默认 最新

  • dongyin2643 2018-06-16 22:32
    关注

    Yes, this is common. Most web apps and web sites do something like this. WordPress, for example, uses a single username and password to access the database. It's fine.

    WordPress keeps its secrets (passwords and some other things) in a file called /wp-config.php. A properly configured web server won't allow a site visitor to see that file directly. It should be set up to always run, and never display, php files when a user asks for those files in a URL. Instead, other parts of the web app include or require it in their code, to get the secrets. WordPress has a good description of this file in their docs.

    If you want slightly tighter security though, I suggest creating four usernames/passwords for your database, and for backups. (Some people use a separate username for backups.)

    1. reporting: This user has only read privileges to your tables, and is used when your web app (or associated utilities) must generate reports or information displays from your data.
    2. general use: This user has read privileges and limited write privileges. For example, this user might be able to read the user table and both read and write the loginlog, posts, and comments tables. This one is used for most routine web app operations.
    3. admin. This user has read and write privileges to all, or almost all tables. The web app uses this user when doing things like creating or deleting users, changing passwords, or performing billing operations.
    4. super. This user's password is never stored in the web app, but rather is used by an administrator to maintain the database. This is the only user that can create, drop, and truncate tables, create and drop views, stored functions, and other database objects. Keeping this user's password off your web server means that a miscreant can't get to it even if they succeed at pwning your web app.

    Then, the user names and passwords of your web app's users will be their own, and not a database access user/password.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效