Search code examples
node.jscouchdbpouchdbcouchdb-nano

Forgot Password function using CouchDB & Node.JS (Nano)


I'm using the PouchDB library on web & react-native.

I'm building a login system (login & sign up - already working), but I'm missing an important function:

Forgot my password!

How can I set a new password using Node.JS -> Nano & CouchDB?

I'm using the _users table on CouchDB. With this library: https://github.com/pouchdb-community/pouchdb-authentication I can login and register with no problems. Such a library does not provide a way to make a function on how to set password. You log in, register (which's just add a document on CouchDB), and the password gets encoded with SHA-256 salt.

So, it gets me wondering, how can I later change that password on CouchDB? Where should I put that information in CouchDB?

Any help to this problem it's higly appreciated.


Solution

  • To change the password, follow this documentation: https://couchdb.readthedocs.io/en/latest/intro/security.html#password-changing

    In summary, you only need to set the new password in the passwordfield. It will be automatically hashed when saved.

    To do so, you will probably need an application layer on top of CouchDB. From there, you can have some validations (make sure the user is authenticated). Then, you can internally use an admin user to update the user document.