Index: Dev/trunk/classes/SurveyDatabaseInterface.php
===================================================================
--- Dev/trunk/classes/SurveyDatabaseInterface.php	(revision 41)
+++ Dev/trunk/classes/SurveyDatabaseInterface.php	(revision 44)
@@ -1,8 +1,7 @@
 <?php
 // Survey database interface class as intermediate for storing data from the site to the RDF database 
-require 'rdfConstants.php';
+require_once 'rdfConstants.php';
 
 // Include RAP Library to write RDF files
-define("RDFAPI_INCLUDE_DIR", "rdfapi/");
 include(RDFAPI_INCLUDE_DIR . "RDFAPI.php");
 
Index: Dev/trunk/classes/SurveyRDFReader.php
===================================================================
--- Dev/trunk/classes/SurveyRDFReader.php	(revision 41)
+++ Dev/trunk/classes/SurveyRDFReader.php	(revision 44)
@@ -130,5 +130,5 @@
 	}
 	
-	public function readSurveyAnswers($qID)
+	public function readSurveyAnswers($questionID)
 	{
 		$querystring = '
@@ -139,5 +139,5 @@
 			{
 				_question		predicates:resource_type	resources:question ;
-								predicates:uid				"' . $qID . '"  ;
+								predicates:uid				"' . $questionID . '"  ;
 								predicates:has_answer		_answer .
 				_answer			predicates:title			?answerTitle								
Index: Dev/trunk/classes/SurveyRDFWriter.php
===================================================================
--- Dev/trunk/classes/SurveyRDFWriter.php	(revision 41)
+++ Dev/trunk/classes/SurveyRDFWriter.php	(revision 44)
@@ -54,5 +54,5 @@
 	public function setApplicationData($applicationID)
 	{
-		$resourceApplication = new Resource(APPLICATION . '/' . $userID);
+		$resourceApplication = new Resource(APPLICATION . '/' . $applicationID);
 				
 		$predicatePartOf = new Resource(PART_OF);
Index: Dev/trunk/classes/UserDatabaseInterface.php
===================================================================
--- Dev/trunk/classes/UserDatabaseInterface.php	(revision 44)
+++ Dev/trunk/classes/UserDatabaseInterface.php	(revision 44)
@@ -0,0 +1,78 @@
+<?php
+
+// Survey class as intermediate for storing data from the site to the RDF database 
+require_once 'rdfConstants.php';
+
+// Include RAP Library to write RDF files
+include(RDFAPI_INCLUDE_DIR . "RDFAPI.php");
+
+class UserDatabaseInterface
+{
+	protected $key = 'CPSsecretKey';
+	
+	protected $userRDFWriter;
+	protected $userRDFReader;
+	
+	public function __construct()
+	{
+		$this->userRDFWriter = new UserRDFWriter();
+		$this->userRDFReader = new UserRDFReader();
+	}
+	
+	public function addNewUser($userInfo)
+	{
+		$userName = $userInfo['username'];
+		$userPassword = $this->RIJNDAEL_encrypt($userInfo['password']);
+		
+		$this->userRDFWriter->addNewUser($userName, $userPassword);
+		$this->userRDFWriter->saveUsers();
+	}
+	
+	public function checkUserName($userName)
+	{
+		$result = false;
+		
+		$resultUser = $this->userRDFReader->getUserNames();
+		
+		if ($resultUser != null)
+		{
+			foreach($resultUser as $user)
+			{
+				$name = substr($user['?name'],9,strlen($user['?name'])-11);
+				if(!strcmp($name ,$userName))
+				{
+					$result = true;
+				}
+			}
+		}
+		
+		return $result;
+	}
+	
+	public function checkUserPassword($userInfo)
+	{
+		$result = false;
+	
+		$userName = $userInfo['username'];
+		$userPassword = $userInfo['password'];
+		
+		$encryptedPasswordLiteral = $this->userRDFReader->getUserPassword($userName);
+		$encryptedPassword = substr($encryptedPasswordLiteral[0]['?password'],9,strlen($encryptedPasswordLiteral[0]['?password'])-11);
+				
+		if(!strcmp($this->RIJNDAEL_encrypt($userPassword),$encryptedPassword))
+			$result = true;
+		
+		return $result;
+	}
+	
+	protected function RIJNDAEL_encrypt($text)
+	{
+		$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
+		$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
+		
+		return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this->key, $text, MCRYPT_MODE_ECB, $iv)); 
+	}
+
+}
+
+?>
Index: Dev/trunk/classes/UserRDFReader.php
===================================================================
--- Dev/trunk/classes/UserRDFReader.php	(revision 41)
+++ Dev/trunk/classes/UserRDFReader.php	(revision 44)
@@ -17,5 +17,5 @@
     }
 	
-	public function readUserInfo($userID)
+	public function getUserNames()
 	{
 		$querystring = '
@@ -26,6 +26,23 @@
 			{
 				_user		predicates:resource_type	resources:user ;
-							predicates:uid				"' . $userID . '"	;
 							predicates:name 			?name 	
+			}';
+			
+		$result = $this->model->sparqlQuery($querystring);
+				
+		return $result;
+	}
+	
+	public function getUserPassword($userName)
+	{
+		$querystring = '
+			PREFIX 	predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
+			PREFIX	resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
+			SELECT 	?password 
+			WHERE 	
+			{
+				_user		predicates:resource_type	resources:user ;
+							predicates:name				"' . $userName . '"	;
+							predicates:password			?password
 			}';
 			
Index: Dev/trunk/classes/UserRDFWriter.php
===================================================================
--- Dev/trunk/classes/UserRDFWriter.php	(revision 41)
+++ Dev/trunk/classes/UserRDFWriter.php	(revision 44)
@@ -22,5 +22,5 @@
 	}
 	
-	public function addNewUser($name)
+	public function addNewUser($name,$password)
 	{
 		$userID = md5( uniqid(rand(), true) );
@@ -32,7 +32,15 @@
 		$this->model->add(new Statement($resourceUser,$predicateRType,$resourceUserType));
 		
+		$literalUserName = new Literal($name);
+		$predicateName = new Resource(NAME);
+		$this->model->add(new Statement($resourceUser,$predicateName,$literalUserName));	
+		
 		$literalUserID = new Literal($userID);
 		$predicateUniqueID = new Resource(UID);
 		$this->model->add(new Statement($resourceUser,$predicateUniqueID,$literalUserID));		
+		
+		$literalPassword = new Literal($password);
+		$predicatePassword = new Resource(PASSWORD);
+		$this->model->add(new Statement($resourceUser,$predicatePassword,$literalPassword));	
 	}
 
