问题描述
如何在CouchDB中创建普通的非管理员用户?
How can I create regular, non-admin users in CouchDB?
推荐答案
首先,将用户放入 _users
数据库。文档的ID必须为 org.couchdb.user:username
,例如
First you put the user in _users
database. The ID of the document must be org.couchdb.user:username
, e.g.
使用CouchDB 1.2.0或稍后使用:
With CouchDB 1.2.0 or later use this:
{
"_id": "org.couchdb.user:dbreader",
"name": "dbreader",
"type": "user",
"roles": [],
"password": "plaintext_password"
}
CouchDB将对&在服务器端为您添加密码,然后将值保存在 password_sha
和 salt
字段中(请参见下文)。
CouchDB will hash & salt the password for you on the server side and save the values in the fields password_sha
and salt
(see below).
使用CouchDB< 1.2.0用户文档应如下所示:
With CouchDB < 1.2.0 the user document needs to look like this:
{
"_id": "org.couchdb.user:dbreader",
"name": "dbreader",
"type": "user",
"roles": [],
"salt": "54935938852dd34f92c672ab31e397cedaf0946d",
"password_sha": "42253ea4461a604f967813aaff90b139d7018806"
}
请注意,CouchDB 1.3.0及更高版本将使用PBKDF2代替aha&
Note that CouchDB 1.3.0 and later will use PBKDF2 instead of aha & salt for hashing the password.
然后,您可以通过在未版本控制的特定数据库中创建ID为_security的id的文档来创建每个数据库身份验证,例如
Then you can create per database authentication by creating document with id _security in specific database which is not versioned, e.g.
{
"admins": {
"names": ["dbadmin"],
"roles": ["editor"]
},
"readers": {
"names": ["dbreader"],
"roles": ["reader"]
}
}
这意味着 _users中有2个用户
和管理员 dbadmin 和 dbreader 。如果您懒得阅读已经建议的文档,那么应该这样做。
This means that there are 2 users in _users
besides the admin dbadmin and dbreader. That should do in case you are too lazy to read the document that has already been suggested.
这篇关于在CouchDB中创建普通用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!