Skip to content

Create users before CouchDB 1.2

Kevin Gaudin edited this page May 24, 2013 · 3 revisions

Creating a User Record

Prior to CouchDB 1.2, creating a user requires to generate an encrypted password yourself.

This requires you to create a salt & hashed password for your first user. In UNIX systems (Linux, Mac OS X), you can do this with command-line utilities

The following command will generate a random salt:

$ SALT=`openssl rand 16 | openssl md5`

And this one will take the salt you just generated and use it to hash the provided password (replace "password" in the command below with the password your want:

$ echo -n "password$SALT" | openssl sha1

Next, we can create a user record. In your favorite text editor, create a JSON document that looks like this

{
    "_id": "org.couchdb.user:[newusername]",
    "name": "[newusername]",
    "type": "user",
    "roles": ["reporter", "reader"],
    "password_sha": "[hashed_password]",
    "salt": "[generated_salt]"
}

POST this document to the _users db to create a record:

$ curl --header "Content-Type: application/json" -X POST -u [adminuser]:[adminpassword] -p https://[your.couchdb.host]:[port]/_users -d '{ "_id": "org.couchdb.user:[newusername]", "name": "[newusername]", "type": "user", "roles": ["reporter", "reader"], "password_sha": "[hashed_password]", "salt": "[generated_salt]" }'
Clone this wiki locally