Index: Dev/branches/jos-branch/server/classes/Auth.php
===================================================================
--- Dev/branches/jos-branch/server/classes/Auth.php	(revision 269)
+++ Dev/branches/jos-branch/server/classes/Auth.php	(revision 285)
@@ -5,21 +5,33 @@
 class Auth {
 
-    public static function login($username, $password) {
-        $user_results = User::get(array("name" => $username));
-        if (!empty($user_results)) {
-            $user = $user_results[0];
-            if (sha1($password) == $user->password) {
-                return $user;
-            }
+    public static function register($email, $password) {
+        $user_results = User::get(array("email" => $email));
+        if ( !empty($user_results) ) {
+            throw new Exception("User with email $email already exists.");
         }
-        return false;
+        $salt = rand();
+        $user = new User(null,$email,sha1($password.$salt),$salt);
+        $user->save();
+        return $user;
+    }
+    
+    public static function login($email, $password) {
+        $user_results = User::get(array("email" => $email));
+        if (empty($user_results)) {
+            throw new Exception("User with email $email not found.");
+        }
+        $user = $user_results[0];
+        if (sha1($password.$user->passwordSalt) != $user->passwordHash) {
+            throw new Exception("Wrong password.");
+        }
+        return $user;
     }
 
     public static function restore($session) {
         $user_results = User::get(array("uid" => $session));
-        if (!empty($user_results)) {
-            return $user_results[0];
+        if (empty($user_results)) {
+            throw new Exception("Session with id $session not found.");
         }
-        return false;
+        return $user_results[0];
     }
     
Index: Dev/branches/jos-branch/server/classes/Marshaller.php
===================================================================
--- Dev/branches/jos-branch/server/classes/Marshaller.php	(revision 285)
+++ Dev/branches/jos-branch/server/classes/Marshaller.php	(revision 285)
@@ -0,0 +1,64 @@
+<?php
+
+class Marshaller {
+
+    const OBJ_TYPE = '__objectType';
+
+    private static function isWrappedObject($obj) {
+        return isset($obj[self::OBJ_TYPE]);
+    }
+
+    public static function marshall($obj) {
+        switch (gettype($obj)) {
+            case 'array':
+                return array_map(array('Marshaller','marshall'), $obj);
+            case 'object':
+                return static::wrapObject($obj);
+            default:
+                return $obj;
+        }
+    }
+
+    private static function wrapObject($obj) {
+        $objectType = get_class($obj);
+        if ($objectType == 'DateTime') {
+            return array(self::OBJ_TYPE => 'DateTime', 'timestamp' => $obj->getTimestamp());
+        } else {
+            $newObj = static::marshall((array) $obj);
+            $newObj[self::OBJ_TYPE] = get_class($obj);
+            return $newObj;
+        }
+    }
+
+    public static function unmarshall($obj) {
+        switch (gettype($obj)) {
+            case 'object':
+                $obj = (array) $obj;
+            case 'array':
+                if (static::isWrappedObject($obj)) {
+                    return static::unwrapObject($obj);
+                } else {
+                    return array_map(array('Marshaller','unmarshall'), $obj);
+                }
+            default:
+                return $obj;
+        }
+    }
+
+    private static function unwrapObject($obj) {
+        $objectType = $obj[self::OBJ_TYPE];
+        unset($obj[self::OBJ_TYPE]);
+        if ($objectType == 'DateTime') {
+            $date = new DateTime();
+            $date->setTimestamp($obj['timestamp']);
+            return $date;
+        } else if (is_subclass_of($objectType, 'ResearchToolObjectInterface')) {
+            return $objectType::create((object)static::unmarshall($obj));
+        } else {
+            return $obj;
+        }
+    }
+
+}
+
+?>
Index: Dev/branches/jos-branch/server/classes/models/Answer.php
===================================================================
--- Dev/branches/jos-branch/server/classes/models/Answer.php	(revision 269)
+++ Dev/branches/jos-branch/server/classes/models/Answer.php	(revision 285)
@@ -18,5 +18,5 @@
 	public static function create($obj)
 	{
-		return new Answer($obj->uid, $obj->question, $obj->values)
+		return new Answer($obj->uid, $obj->question, $obj->values);
 	}
 
Index: Dev/branches/jos-branch/server/classes/models/AnswerSet.php
===================================================================
--- Dev/branches/jos-branch/server/classes/models/AnswerSet.php	(revision 269)
+++ Dev/branches/jos-branch/server/classes/models/AnswerSet.php	(revision 285)
@@ -187,4 +187,9 @@
 		return $answers;
 	}
+
+    public static function create($obj) {
+        return new AnswerSet($obj->uid, $obj->survey, $obj->respondent, $obj->datetime, $obj->answers);
+    }
+    
 }
 
Index: Dev/branches/jos-branch/server/classes/models/Application.php
===================================================================
--- Dev/branches/jos-branch/server/classes/models/Application.php	(revision 269)
+++ Dev/branches/jos-branch/server/classes/models/Application.php	(revision 285)
@@ -113,4 +113,8 @@
         return $applications;
 	}
+
+    public static function create($obj) {
+        return new Application($obj->uid, $obj->title, $obj->description, $obj->style);
+    }
 }
 
Index: Dev/branches/jos-branch/server/classes/models/ApplicationInstance.php
===================================================================
--- Dev/branches/jos-branch/server/classes/models/ApplicationInstance.php	(revision 269)
+++ Dev/branches/jos-branch/server/classes/models/ApplicationInstance.php	(revision 285)
@@ -167,4 +167,10 @@
 
 	}
+
+    public static function create($obj) {
+        return new ApplicationInstance($obj->uid, $obj->application, 
+                $obj->starttime, $obj->endtime, $obj->open, $obj->playerresults,
+                $obj->groupresults, $obj->periodicresults);
+    }
 }
 ?>
Index: Dev/branches/jos-branch/server/classes/models/ResearchToolObject.php
===================================================================
--- Dev/branches/jos-branch/server/classes/models/ResearchToolObject.php	(revision 269)
+++ Dev/branches/jos-branch/server/classes/models/ResearchToolObject.php	(revision 285)
@@ -11,8 +11,12 @@
 
 
-abstract class ResearchToolObject {
+abstract class ResearchToolObject implements ResearchToolObjectInterface {
 
-	public $uid;
+	public $uid = null;
 
+    public function getUid() {
+        return $this->uid;
+    }
+    
 	public function evaluate()
 	{
@@ -79,3 +83,11 @@
 }
 
+interface ResearchToolObjectInterface {
+    function getUid();
+    static function get($arguments);
+    static function create($obj);
+    function evaluate();
+    function save();
+}
+
 ?>
Index: Dev/branches/jos-branch/server/classes/models/Respondent.php
===================================================================
--- Dev/branches/jos-branch/server/classes/models/Respondent.php	(revision 269)
+++ Dev/branches/jos-branch/server/classes/models/Respondent.php	(revision 285)
@@ -16,5 +16,6 @@
 
 	public $email;
-	public $password;
+	public $passwordHash;
+	public $passwordSalt;
 
 	/**
@@ -24,5 +25,5 @@
 	 * @param type password
 	 */
-	public function __construct($uid = null, $email = null, $password = null)
+	public function __construct($uid = null, $email = null, $passwordHash = null, $passwordSalt = null)
 	{
       	if(!isset($uid))
@@ -33,5 +34,6 @@
       	$this->uid = $uid;
      	$this->email = $email;
-      	$this->password = $password;
+      	$this->passwordHash = $passwordHash;
+      	$this->passwordSalt = $passwordSalt;
 	}
     /**
@@ -64,7 +66,12 @@
         $model->add(new Statement($resourceRespondent,$predicateName,$literalRespondentName));			
 
-        $literalPassword = new Literal($this->password);
-        $predicatePassword = new Resource(PASSWORD);
-        $model->add(new Statement($resourceRespondent,$predicatePassword,$literalPassword));
+        $literalPasswordHash = new Literal($this->passwordHash);
+        $predicatePasswordHash = new Resource(PASSWORDHASH);
+        $model->add(new Statement($resourceRespondent,$predicatePasswordHash,$literalPasswordHash));
+        
+        $literalPasswordSalt = new Literal($this->passwordSalt);
+        $predicatePasswordSalt = new Resource(PASSWORDSALT);
+        $model->add(new Statement($resourceRespondent,$predicatePasswordSalt,$literalPasswordSalt));
+        
 		$model->saveAs(Respondent::$filename, 'rdf');
 		return true;
@@ -85,5 +92,5 @@
             PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
             PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
-            SELECT ?uid, ?email, ?password
+            SELECT ?uid, ?email, ?passwordHash, ?passwordSalt
             WHERE 	
             {
@@ -91,5 +98,6 @@
 					predicates:uid ?uid ;
 					predicates:email ?email ;
-					predicates:password ?password ;
+					predicates:passwordHash ?passwordHash ;
+					predicates:passwordSalt ?passwordSalt ;
 					' . ResearchToolObject::createArguments($arguments) .  '
             }';
@@ -102,13 +110,15 @@
             foreach($results as $result)
             { 
-                    $respondents[] = new Respondent($result['?uid']->label, $result['?email']->label, $result['?password']->label);
+                    $respondents[] = new Respondent($result['?uid']->label, $result['?email']->label, $result['?passwordHash']->label, $result['?passwordSalt']->label);
             }
         }
         return $respondents;
 	}
+
+    public static function create($obj) {
+        return new Respondent($obj->uid, $obj->email, $obj->passwordHash, $obj->passwordSalt);
+    }
+
 }
 
-	
-
-
-
+?>
Index: Dev/branches/jos-branch/server/classes/models/ResultSet.php
===================================================================
--- Dev/branches/jos-branch/server/classes/models/ResultSet.php	(revision 269)
+++ Dev/branches/jos-branch/server/classes/models/ResultSet.php	(revision 285)
@@ -158,3 +158,8 @@
 		return $answersets;
 	}
+
+    public static function create($obj) {
+        return new ResultSet($obj->uid, $obj->answersets, $obj->playerresults, 
+                $obj->groupresults, $obj->periodicresults);
+    }
 }
Index: Dev/branches/jos-branch/server/classes/models/Session.php
===================================================================
--- Dev/branches/jos-branch/server/classes/models/Session.php	(revision 269)
+++ Dev/branches/jos-branch/server/classes/models/Session.php	(revision 285)
@@ -24,8 +24,8 @@
 	 * @param type $title
 	 * @param type $creator
-	 * @param type $datetime
+	 * @param type $creationdate
 	 * @param type $pipeline
 	 */
-	public function __construct($uid = null, $title = null, $creator = null, $datetime = null, $pipeline = null)
+	public function __construct($uid = null, $title = null, $creator = null, $creationdate = null, $pipeline = null)
 	{
 		if(!isset($uid))
@@ -36,5 +36,5 @@
 		$this->title = $title;
 		$this->creator = $creator;
-		$this->creationdate = $datetime;
+		$this->creationdate = $creationdate;
 		$this->pipeline = $pipeline;
 	}
@@ -141,7 +141,6 @@
 			}
 		}
-
-		$model->saveAs(Session::$filename, 'rdf');
-		return true;
+		
+		return $model->saveAs(Session::$filename, 'rdf');
 	}
 
@@ -320,6 +319,10 @@
 	}
 
+    public static function create($obj) {
+        return new Session($obj->uid, $obj->title, $obj->creator,
+                $obj->creationdate, $obj->pipeline);
+    }
+
 }	
 
-
 ?>
Index: Dev/branches/jos-branch/server/classes/models/SessionInstance.php
===================================================================
--- Dev/branches/jos-branch/server/classes/models/SessionInstance.php	(revision 269)
+++ Dev/branches/jos-branch/server/classes/models/SessionInstance.php	(revision 285)
@@ -235,4 +235,11 @@
 	}
 
+    public static function create($obj) {
+        return new SessionInstance($obj->uid, $obj->title, $obj->location,
+                $obj->facilitator, $obj->starttime, $obj->endtime, $obj->notes,
+                $obj->session, $obj->resultset);
+    }
 
 }
+
+?>
Index: Dev/branches/jos-branch/server/classes/models/Survey.php
===================================================================
--- Dev/branches/jos-branch/server/classes/models/Survey.php	(revision 269)
+++ Dev/branches/jos-branch/server/classes/models/Survey.php	(revision 285)
@@ -169,4 +169,8 @@
     }
 
+    public static function create($obj) {
+        return new Survey($obj->uid, $obj->title, $obj->description,
+                $obj->creator, $obj->questions);
+    }
 
 }
Index: Dev/branches/jos-branch/server/classes/models/SurveyInstance.php
===================================================================
--- Dev/branches/jos-branch/server/classes/models/SurveyInstance.php	(revision 269)
+++ Dev/branches/jos-branch/server/classes/models/SurveyInstance.php	(revision 285)
@@ -26,5 +26,5 @@
      * @param type $answersets: A list of answersets.
      */
-    public function __construct($uid, $survey, $starttime, $endtime, $open, $presetanswers, $answersets)
+	public function __construct($uid = null, $survey = null, $starttime = null, $endtime = null, $open = null, $presetanswers = null, $answersets = null)
     {
         if(!isset($uid))
Index: Dev/branches/jos-branch/server/classes/models/User.php
===================================================================
--- Dev/branches/jos-branch/server/classes/models/User.php	(revision 269)
+++ Dev/branches/jos-branch/server/classes/models/User.php	(revision 285)
@@ -17,5 +17,6 @@
     
     public $email;
-    public $password;
+    public $passwordHash;
+    public $passwordSalt;
     
     /**
@@ -23,5 +24,5 @@
      * If the user does not yet exist in the database, call with null as first parameter
      */
-    public function __construct($uid = null, $email = null, $password = null) {
+    public function __construct($uid = null, $email = null, $passwordHash = null, $passwordSalt = null) {
         if(!isset($uid))
         {
@@ -30,5 +31,6 @@
         $this->uid = $uid;
 		$this->email = $email;
-        $this->password = sha1($password);
+        $this->passwordHash = $passwordHash;
+        $this->passwordSalt = $passwordSalt;
 	}
 
@@ -60,7 +62,11 @@
         $model->add(new Statement($resourceUser,$predicateName,$literalUserName));			
 
-        $literalPassword = new Literal($this->password);
-        $predicatePassword = new Resource(PASSWORD);
-		$model->add(new Statement($resourceUser,$predicatePassword,$literalPassword));
+        $literalPasswordHash = new Literal($this->passwordHash);
+        $predicatePasswordHash = new Resource(PASSWORDHASH);
+		$model->add(new Statement($resourceUser,$predicatePasswordHash,$literalPasswordHash));
+
+        $literalPasswordSalt = new Literal($this->passwordSalt);
+        $predicatePasswordSalt = new Resource(PASSWORDSALT);
+		$model->add(new Statement($resourceUser,$predicatePasswordSalt,$literalPasswordSalt));
 
 		$model->saveAs(User::$filename, 'rdf');
@@ -82,5 +88,5 @@
             PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
             PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
-            SELECT ?uid, ?email, ?password
+            SELECT ?uid, ?email, ?passwordHash, ?passwordSalt
             WHERE 	
             {
@@ -88,5 +94,6 @@
 					predicates:uid ?uid ;
 					predicates:email ?email ;
-					predicates:password ?password ;
+					predicates:passwordHash ?passwordHash ;
+					predicates:passwordSalt ?passwordSalt ;
 					' . ResearchToolObject::createArguments($arguments) . '
             }';
@@ -99,9 +106,14 @@
             foreach($results as $result)
             { 
-				$users[] = new User($result['?uid']->label, $result['?email']->label, $result['?password']->label);
+				$users[] = new User($result['?uid']->label, $result['?email']->label, $result['?passwordHash']->label, $result['?passwordSalt']->label);
             }
         }
         return $users;
 	}
+
+    public static function create($obj) {
+        return new User($obj->uid, $obj->email,$obj->passwordHash,$obj->passwordSalt);
+    }
+
 }
 
