Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create user accounts in MongoDB?

Tags:

mongodb

I wonder what's 'correct' way to create user accounts in MongoDB and actions like register/login. Do I have to create a specific collection for users (Username,Email,Password) or MongoDB has something built in already for users?

If I have to create users collection manually, how to deal with password encryption? Thanks.

like image 941
Stewie Griffin Avatar asked Oct 08 '10 13:10

Stewie Griffin


2 Answers

You'll probably have to create and manage the collection of users manually.

As for encrypting passwords, the common approach is to hash the passwords using a suitable hash-function before you store them in the db. Later, when a user tries to login you use the same hash-function on the string they entered in the password field and compare that result to the password entry in your db. That way you never store the actual passwords and if someone hacks you they won't get your users passwords, just their hashes.

For extra security (against dictionary attacks) you should also salt the hashed passwords. Read about it here

like image 119
Jakob Avatar answered Sep 20 '22 03:09

Jakob


Mongo is for data persistance, what you are talking about is much higher level. A better question would be "How to do user authentication for <language or platform you are using> with mongo"

like image 30
Matt Briggs Avatar answered Sep 23 '22 03:09

Matt Briggs