Reputation: 6657
I use Cassandra in my project, and I need to store info about users (email, username, password, first name and other additional information). This data also used for authorization purposes.
I'm new to designing databases for Cassandra's data model. So, I need your help to understand if I've done this correctly.
I have the keyspace named "users". In this keyspace I use the user's email as the primary key. I have the following column families: first name, last name, username, password.
The main question is the following: is it a good idea to use the email as the key for this?
For the password - is it good to store the MD5 hash of it, or is there a better practice for this?
UPD I have a misprint above. I mean - one keyspace as database "Test", one column family "Users" - collection of user's info and a lot of separate columns for each user's property.
Upvotes: 2
Views: 2703
Reputation: 42607
You don't need a separate column family for each property of the user. You can put them all in a single column family, with multiple columns, for example:
key -> firstname lastname username password
John Smith jsmith 1AB3C4GA16GH134G
The design depends on what lookups you want to do. If you only need to lookup users by their email address, then what you propose is fine. But what happens when a user changes their email address? If usernames are fixed, then keying on username may be simpler...
[UPDATE] If you always retrieve all the user data at once, and you only retrive data by key, then you could of course store all the info embedded in a single column, as JSON or similar. However, you then lose any ability to look up users by name, username, etc.
Upvotes: 3
Reputation: 25150
Using the email as a key is fine if that is how you lookup your users and email is unique. If you lookup your users by username and username is unique, then use username as the key. If you need to lookup by username and email, then you will need a second column family to map username->email.
Don't store the plain text password. Even storing the md5 of the password and a salt is not sufficient. See this post
Upvotes: 3