Search code examples
javacassandrahector

How to authenticate a user using Cassandra database


I want to create a way to authenticate users. In mysql I do:

SELECT user_id FROM customers WHERE `username` = 'the_username' AND `password` = 'the_password' 

If the query doesn't return an empty resultset then user is authorized. Cassandra expects me to know the row key (user_id) upfront. How can I check all rows in a column family for existence of a username and password where I don't know the row key.

I am using Hector api to connect to Cassandra 1.2.2


Solution

  • Some possible solutions:

    1. use the username as row key
    2. create a secondary index on username

    I would use the first one. If username is unique (as I assume), you don't need user_id