openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

DBVersion000006.class.php (947B)


      1 <?php
      2 
      3 namespace cms\update\version;
      4 
      5 use database\DbVersion;
      6 use database\Column;
      7 
      8 /**
      9  * Security enhancements.
     10  * 
     11  * @author dankert
     12  *
     13  */
     14 class DBVersion000006 extends DbVersion
     15 {
     16 	public function update()
     17 	{
     18 		$table = $this->table('user');
     19 
     20 		$table->column('password_expires')->type(Column::TYPE_INT)->size(0)->nullable()->add();
     21 		
     22 		$table->column('last_login'      )->type(Column::TYPE_INT)->size(0)->nullable()->add();
     23 		
     24 		$table->column('password_algo'   )->type(Column::TYPE_INT)->size(0)->defaultValue(2)->add();
     25 		
     26 		// Setting Password algo. Passwords beginning with '$' are (old) MD5-hashes. 
     27 		
     28 		// SUBSTR(s,pos,length) is supported by MySql,Postgres,SQLite
     29 		// SUBSTRING(s FROM pos FOR length) is NOT supported by SQLite
     30 		$db    = $this->getDb();
     31 		$updateAlgoStmt = $db->sql('UPDATE '.$table->getSqlName().
     32 				' SET password_algo=1 WHERE SUBSTR(password_hash,1,1) = '."'$'".';'
     33 		);
     34 		$updateAlgoStmt->execute();
     35 		
     36 	}
     37 }