Index: /Dev/trunk/classes/SurveyDatabaseInterface.php
===================================================================
--- /Dev/trunk/classes/SurveyDatabaseInterface.php	(revision 43)
+++ /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 43)
+++ /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 43)
+++ /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 43)
+++ /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 43)
+++ /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));	
 	}
 
Index: /Dev/trunk/index.php
===================================================================
--- /Dev/trunk/index.php	(revision 43)
+++ /Dev/trunk/index.php	(revision 44)
@@ -1,3 +1,22 @@
 <?php require 'classes/master.php'; //should be at top of every page   
+
+if(isset($_POST['login']))
+{
+	if($_POST['username'] == '')
+		die("Please log in!");
+	else
+	{
+		$userDBI = new UserDatabaseInterface();
+		$user_exists = $userDBI->checkUserName($_POST['username']);
+		if($user_exists)
+		{	
+			$correct_password = $userDBI->checkUserPassword($_POST);
+			if(!$correct_password)
+				die("The password you entered is not correct!");
+		}	
+		else
+			die("Unknown user name");
+	}	
+}
 
 /* make an array of survey mock objects */
Index: /Dev/trunk/login.php
===================================================================
--- /Dev/trunk/login.php	(revision 44)
+++ /Dev/trunk/login.php	(revision 44)
@@ -0,0 +1,50 @@
+<?php require 'classes/master.php'; //should be at top of every page
+
+if(isset($_POST['register']))
+{
+	if($_POST['username'] != null && $_POST['password'] != null)
+	{
+		$userDBI = new UserDatabaseInterface();
+		$user_exists = $userDBI->checkUserName($_POST['username']);
+		if(!$user_exists)
+		{
+			$userDBI->addNewUser($_POST);
+		}
+		else
+			echo "Username already exists, try something else";
+	}
+	else
+		echo "please fill in a username and password";
+}
+?>
+
+<!DOCTYPE html>
+<html>
+    <head>
+        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+        <title>Facilitator</title>
+        <link rel="stylesheet" type="text/css" href="css/style.css" />
+        <script type="text/javascript" src="js/menu.js"></script>
+    </head>
+    <body>
+        <div id="header">
+                <?php new Logo(); ?>
+            </div>
+        
+        <div id="wrapper">
+            
+            <div id="content">
+                <form action="index.php" method="POST">
+					Username:<br />
+					<input type="text" name="username"><p />
+					Password:<br />
+					<input type="password" name="password"><p />
+					<input type="submit" name="login" value="Log in">
+				</form>
+                <form action="register.php" method="POST">
+					<input type="submit" name="register" value="Register">
+				</form>
+            </div>
+        </div>
+    </body>
+</html>
Index: /Dev/trunk/rdfConstants.php
===================================================================
--- /Dev/trunk/rdfConstants.php	(revision 43)
+++ /Dev/trunk/rdfConstants.php	(revision 44)
@@ -1,3 +1,5 @@
 <?php
+define("RDFAPI_INCLUDE_DIR", "rdfapi/");
+
 // Constants for defining namespaces, resources, predicates, datatypes, questiontypes for RDF database
 
@@ -18,4 +20,5 @@
 define('CREATOR',SURVEYTOOL_PREDICATES_NAMESPACE . 'creator');
 define('NAME',SURVEYTOOL_PREDICATES_NAMESPACE . 'name');
+define('PASSWORD',SURVEYTOOL_PREDICATES_NAMESPACE . 'password');
 define('TITLE',SURVEYTOOL_PREDICATES_NAMESPACE . 'title');
 define('DESCRIPTION',SURVEYTOOL_PREDICATES_NAMESPACE . 'description');
Index: /Dev/trunk/register.php
===================================================================
--- /Dev/trunk/register.php	(revision 44)
+++ /Dev/trunk/register.php	(revision 44)
@@ -0,0 +1,31 @@
+<?php require 'classes/master.php'; //should be at top of every page
+
+?>
+
+<!DOCTYPE html>
+<html>
+    <head>
+        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+        <title>Facilitator</title>
+        <link rel="stylesheet" type="text/css" href="css/style.css" />
+        <script type="text/javascript" src="js/menu.js"></script>
+    </head>
+    <body>
+        <div id="header">
+                <?php new Logo(); ?>
+            </div>
+        
+        <div id="wrapper">
+            
+            <div id="content">
+                <form action="login.php" method="POST">
+					Username:<br />
+					<input type="text" name="username"><p />
+					Password:<br />
+					<input type="password" name="password"><p />
+					<input type="submit" name="register" value="Register">
+				</form>
+            </div>
+        </div>
+    </body>
+</html>
Index: /Dev/trunk/submitsurvey.php
===================================================================
--- /Dev/trunk/submitsurvey.php	(revision 43)
+++ /Dev/trunk/submitsurvey.php	(revision 44)
@@ -2,93 +2,4 @@
 require 'classes/master.php';
 
-require 'rdfConstants.php';
-
-// Include RAP Library to write RDF files
-define("RDFAPI_INCLUDE_DIR", "rdfapi/");
-include(RDFAPI_INCLUDE_DIR . "RDFAPI.php");
-
-$surveyRDFWriter = new SurveyRDFWriter();
-
-$sTitle = $_POST['surveyTitle'];
-$sDesription = $_POST['surveyDescription'];
-
-$surveyRDFWriter->createSurvey($sTitle,$sDesription);
-
-$qNumber = 1;
-do
-{
-	$qTitle = $_POST['questionTitle'.$qNumber];
-	$qDescription = $_POST['questionDescription'.$qNumber];
-	$qType = $_POST['questionType'.$qNumber];
-
-	if ($qTitle != null) 
-	{
-		$qaArray = array();
-		$aNumber = 1;
-		do
-		{
-			$aTitle = $_POST['q'.$qNumber.'ans'.$aNumber];
-			if ($aTitle != null) 
-			{
-				$aArray = array();
-				$aArray['Title'] = $aTitle;
-				$aArray['Description'] = 'answerDescription'.$aNumber;
-				$qaArray[] = $aArray;
-			}
-			$aNumber++;
-		} while ($aTitle != null);
-				
-		$qNumber++;
-		$surveyRDFWriter->addQuestion($qTitle,$qDescription,$qType,$qaArray);
-	}
-} while($qTitle != null);
-
-
-$surveyRDFWriter->saveSurvey($sTitle);
-
-echo 'Done<br/><br/>';
-
-$surveyRDFReader = new SurveyRDFReader();
-
-$surveyRDFReader->loadSurvey($sTitle);
-
-$result = $surveyRDFReader->readSurveyTitle();
-
-foreach($result as $line){
-  $value = $line['?title'];
-    if($value != "")
-      echo $value->toString().'<br/>';
-    else
-      echo 'undbound<br/>';
-}
-
-$result2 = $surveyRDFReader->readSurveyDescription();
-
-foreach($result2 as $line){
-  $value = $line['?description'];
-    if($value != "")
-      echo $value->toString().'<br/>';
-    else
-      echo 'undbound<br/>';
-}
-
-$result3 = $surveyRDFReader->readSurveyQuestions($sTitle);
-
-if($result3 != null)
-{
-	var_dump($result3);
-	 
-	foreach($result3 as $line){
-	  $value = $line['?questionTitle'];
-		if($value != "")
-		  echo '<br/>'.'<br/>'.$value->toString().'<br/>';
-		else
-		  echo 'undbound<br/>';
-	}
-} else
-{
-	echo '<"Literal("'.$sTitle.'")"> empty result <br/>';
-}
-echo '<br/>';
 var_dump($_POST);
 
Index: /Dev/trunk/surveycreation.php
===================================================================
--- /Dev/trunk/surveycreation.php	(revision 43)
+++ /Dev/trunk/surveycreation.php	(revision 44)
@@ -49,7 +49,7 @@
 
             <div id="content">
-<?php
-new SurveyCreationTool($savedSurvey, $timeStamp);
-?>
+				<?php
+				new SurveyCreationTool($savedSurvey, $timeStamp);
+				?>
             </div>
         </div>
