简体   繁体   English

数据库访问的用户管理

[英]User Management for Database Access

I am very new to programming and have a theory-based question relating to user management in databases. 我对编程非常陌生,并且有一个与数据库中的用户管理有关的基于理论的问题。 I can't quite think how this would be asked so if it's a repeat question please feel free to link. 我不太想怎么问这个问题,因此,如果是重复问题,请随时链接。

tldr: The core problem is that a new user needs a connection to the database in order to perform CREATE USER... but to establish that connection, they need to have been CREATE-d already at some point. tldr:核心问题是新用户需要连接到数据库才能执行CREATE USER ...,但是要建立该连接,他们需要在某个时候已经CREATE-d。

Full Question: 完整问题:

If I have a database that I want to allow multiple users to access, I understand that the administrator can create "server-side" users (via CREATE USER), with credentials selected by the user. 如果我有一个要允许多个用户访问的数据库,那么我知道管理员可以使用用户选择的凭据来创建“服务器端”用户(通过CREATE USER)。 The database connection can be opened by each user through a login page by inputting their credentials which are subsequently passed in as arguments to the new connection. 每个用户都可以通过登录页面打开数据库连接,方法是输入其凭据,然后将其作为参数传递给新连接。

However, what if I want to eliminate the need for an administrator to set up new user accounts? 但是,如果我想消除管理员设置新用户帐户的需求,该怎么办? That is I want the end user to navigate to a register page, where they choose credentials, hit register and can get access to the database. 那就是我希望最终用户导航到注册页面,他们在其中选择凭据,点击注册并可以访问数据库。

My current understanding is that the only way to do this is to create "pseudo-user" accounts. 我目前的理解是,唯一的方法就是创建“伪用户”帐户。 ie the registration is simply inserting the new user credentials into a credentials table. 即注册只是将新的用户凭据插入凭据表中。 Subsequently all users "log in" through the same connection, but must first clear a login page which checks that their input credentials match the ones stored in the credentials table. 随后,所有用户都通过同一连接“登录”,但必须首先清除登录页面,该页面检查其输入凭据是否与凭据表中存储的凭据匹配。 (This would still need the administrator to create a "real" user with the appropriate privileges, otherwise everyone would be connecting through the root user). (这仍然需要管理员创建具有适当特权的“真实”用户,否则每个人都将通过root用户进行连接)。

edit: I meant to say this is via php. 编辑:我的意思是说这是通过php。

Does this sound right? 听起来对吗?

Thank you community. 谢谢社区。

You dont need for each user, that visit your page, an MYSQL user-account. 您不需要访问页面的每个用户一个MYSQL用户帐户。 Go and set up some MYSQL User Accounts for groubs, like: 去为groubs设置一些MYSQL用户帐户,例如:

PUBLIC_USER for all user, that arent logged in with less rights. 对于所有用户PUBLIC_USER,该用户以较少的权限登录。

PROTECTED_USER for logged user with more right. PROTECTED_USER,用于具有更多权限的登录用户。

PRIVATE_USER for users with maximal right, but less rights as you ROOT account. PRIVATE_USER适用于拥有最大权限,但随着您的ROOT帐户拥有较少权限的用户。

You can make more groubs if needed, but dont make an MYSQL User Account for each visitor of you page. 如果需要,您可以制作更多的小玩意,但不要为您页面的每个访问者创建一个MYSQL用户帐户。

There is really no need for. 确实没有必要。

It is very bad practise to let visitor run script that creates user in/for MYSQL. 让访问者运行在/ SQL中创建用户的脚本是非常不好的做法。

And for the hole user/visitor Account Management create a table for it, dont you the MYSQL core tables. 为漏洞用户/访问者帐户管理创建一个表,不要使用MYSQL核心表。

eg user_account with username, password, .... 例如,user_account带有用户名,密码等。

You mixing users of the app, with database users. 您将应用程序的用户与数据库用户混合在一起。 They are rarely, if ever, the same thing. 它们很少(如果有的话)是同一件事。

Your app needs a single user account for mysql, but your app needs to track its own users in the database -- typically in a table called something like app_users . 您的应用程序需要一个用于mysql的单一用户帐户,但是您的应用程序需要在数据库中跟踪其自己的用户-通常在名为app_users类的表中。 A table that might look like: 一个表可能看起来像:

 id   username   email   passwd_hash   salt
 --   --------   -----   -----------   ----
 01   fred       f@a.c   sdfasdf3r23   asdwer32

The user of the web app will never have permission directly to the database, but all the application queries will be run through the app's account. Web应用程序的用户永远不会直接拥有数据库权限,但是所有应用程序查询都将通过该应用程序的帐户运行。 Those queries should be either prepared statements, or prepared statements executing only stored procedures. 这些查询应该是预备语句,或者是仅执行存储过程的预备语句。 The app account shouldn't be allowed to alter the schema. 不应允许该应用程序帐户更改架构。 The app credentials the app will need to connect to the database should be encrypted and stored outside of the web root, but in a folder that the OS user the web server runs as has access to read. 应用程序需要将其连接到数据库的应用程序凭据应经过加密,并存储在Web根目录之外,但应存储在OS用户中,Web服务器以运行该文件夹的权限读取。

You may have more than one app account for mysql, for various levels of permission, but those are still not the same as user accounts stored in the database. 对于各种权限级别,您可能具有多个用于mysql的应用程序帐户,但是这些帐户仍然与数据库中存储的用户帐户不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM