Does anyone know if it's possible for me to change a password in couchdb 1.2? To create a user I have a form that gets a user's information and then posts to the _users database like this ('users' in the url below is proxied):
// Create a user
var userObj = {
_id: "org.couchdb.user:test",
type: "user",
name: "test",
roles: ["user"],
emailAddress: "[email protected]",
firstName: "Test",
lastName: "Test",
password: "password"
};
$.ajax({
url: "/users/org.couchdb.user:test",
type: "PUT",
dataType: "json",
contentType:"application/json",
data: JSON.stringify(userObj)
});
Couchdb 1.2 generates the password hash and salt for me and stores the user. It works great. To update the password, I tried retrieving the user, deleting the password_sha and salt fields, adding a password field and then reposting the document. I was hoping Couch would just recalculate the password_sha and salt fields for me and update the document, but it doesn't. The password_sha and salt fields aren't updated.
// Update a user
$.get("/users/org.couchdb.user:test")
.done(function(userDoc){
delete userDoc.password_sha;
delete userDoc.salt
userDoc.password = "test";
$.ajax({
url: "/users/org.couchdb.user:test",
type: "PUT",
dataType: "json",
contentType:"application/json",
data: userDoc
});
});
I suspect couch will only generate the password_sha and salt fields when the document is created. If that's the case, should I just generate my own password_sha and salt fields and post those in the updated doc instead? Am I missing something here?
Thanks!
Never mind. I was trying to update a JSON string...doh! Just need to parse userDoc, add a password, and then resubmit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With