13

I am using jquery.couch.js to do signup/login/logout to a CouchDB _users database in my Sproutcore application. Is anyone aware of a method for changing user _id and password?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Logic Artist
  • 1,006
  • 11
  • 23

2 Answers2

24

As far as I know the user id cannot be changed but the password can.

The CouchDB documentation describes the process of changing a user password in detail, short:

  • Get the org.couchdb.user:<myuser> document

  • Add a password field with the plaintext password

  • Store the document back to the _users database

As soon as the document is in the database, the CouchDB rehashes the plaintext password using PBKDF2 (at least since CouchDB 1.3).

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Doc Brown
  • 422
  • 5
  • 9
7

Unfortunately, there is no built-in API to do this. The best thing for now is to read the jquery.couch.js code for account creation and use the same code or algorithms to do account modification.

Specifically, you need to update the password_sha and salt values to change a password. To change a user name, you must make a new document, then delete the old document. Just keep the _id and name values in sync and you'll be okay.

JasonSmith
  • 72,674
  • 22
  • 123
  • 149
  • Thanks for the tip. I suspected that creating a new user/deleting the old would be the way to go if there wasn't a modification api. I'll give it a try. – Logic Artist Apr 06 '11 at 17:23