Showing posts with label database. Show all posts
Showing posts with label database. Show all posts

Saturday, December 1, 2018

Cassandra - Data modeling



Cassandra is a NoSQL data base. Some core features that are provided by Cassandra are -

  1. High write performance
  2. High scalability
  3. Fault tolerant
  4. Linear scale performance
  5. Easy data distribution

The Cassandra data model contains -
  1. Keyspaces - A keyspace is the container of all data in Cassandra. Replication is specified at the keyspace level.
  2. Tables - Every table should have a primary key, which can be a composite primary key.
  3. Columns - A column contains the key value data in Cassandra.


Cassandra provides CREATE TABLE, ALTER TABLE, and DROP TABLE statements for data definition and provides INSERT, UPDATE, SELECT, and DELETE statements for data manipulation. The ‘where’ clauses in Cassandra have restrictions. Certain filters in the where clause can result in cluster wide scans which are not desirable.

While doing data modeling for your application, some things to keep in mind would be -
  1. Start with what kind of queries you will be performing on the database.
  2. Denormalize when you can.
  3. Data should be spread evenly across the cluster. This can be achieved by picking the right partition key. The partition key is the first element of the primary key. Data is partitioned by the first part of the primary key and clustered by the remaining part.
  4. Minimize the number of partitions that need to be accessed in your read queries.






Tuesday, August 24, 2010

Yii - Authentication from mysql database using a md5 password

Before proceeding make sure the database has been connected to Yii application. (see previous post)
For this example, the passwords are stored in the database as md5 hash.
You may be required to change the password encoding scheme.

Edit the authenticate method in ../my_app/protected/components/UserIdentity.php to look like this -

public function authenticate()
    {
        //$users=array(
            // username => password
            //'demo'=>'demo',
            //'admin'=>'admin',
        //);
       
        $user = myUsersTable::model()->findByAttributes( array( 'my_userid_column_name' => $this->username));
        if ($user===null) { // No user was found!
            $this->errorCode=self::ERROR_USERNAME_INVALID;
        }
        // $user->Password refers to the "password" column name from the database
        else if($user->Password !== md5("my_salt1".$this->password))
        {   
            $this->errorCode=self::ERROR_PASSWORD_INVALID;
        }
        else { // User/pass match
            $this->errorCode=self::ERROR_NONE;
        }       
        return !$this->errorCode;
    }

Enter the username/password pair on the login page and you should be good to go.