1 | <?php
|
---|
2 |
|
---|
3 | // Survey class as intermediate for storing data from the site to the RDF database
|
---|
4 | require_once 'rdfConstants.php';
|
---|
5 |
|
---|
6 | // Include RAP Library to write RDF files
|
---|
7 | include(RDFAPI_INCLUDE_DIR . "RDFAPI.php");
|
---|
8 |
|
---|
9 | class UserDatabaseInterface
|
---|
10 | {
|
---|
11 | protected $key = 'CPSsecretKey';
|
---|
12 |
|
---|
13 | protected $userRDFWriter;
|
---|
14 | protected $userRDFReader;
|
---|
15 |
|
---|
16 | public function __construct()
|
---|
17 | {
|
---|
18 | $this->userRDFWriter = new UserRDFWriter();
|
---|
19 | $this->userRDFReader = new UserRDFReader();
|
---|
20 | }
|
---|
21 |
|
---|
22 | public function addNewUser($userInfo)
|
---|
23 | {
|
---|
24 | $userName = $userInfo['username'];
|
---|
25 | $userPassword = $this->RIJNDAEL_encrypt($userInfo['password']);
|
---|
26 |
|
---|
27 | if($this->checkUserName($userName))
|
---|
28 | {
|
---|
29 | $this->userRDFWriter->addNewUser($userName, $userPassword);
|
---|
30 | $this->userRDFWriter->saveUsers();
|
---|
31 | }
|
---|
32 | }
|
---|
33 |
|
---|
34 | public function checkUserName($userName)
|
---|
35 | {
|
---|
36 | $result = false;
|
---|
37 |
|
---|
38 | $resultUser = $this->userRDFReader->getUserNames();
|
---|
39 |
|
---|
40 | if ($resultUser != null)
|
---|
41 | {
|
---|
42 | foreach($resultUser as $user)
|
---|
43 | {
|
---|
44 | $name = $user['?name']->label;
|
---|
45 | if(!strcmp($name ,$userName))
|
---|
46 | {
|
---|
47 | $result = true;
|
---|
48 | }
|
---|
49 | }
|
---|
50 | }
|
---|
51 |
|
---|
52 | return $result;
|
---|
53 | }
|
---|
54 |
|
---|
55 | public function checkUserPassword($userInfo)
|
---|
56 | {
|
---|
57 | $result = false;
|
---|
58 |
|
---|
59 | $userName = $userInfo['username'];
|
---|
60 | $userPassword = $userInfo['password'];
|
---|
61 |
|
---|
62 | $encryptedPasswordLiteral = $this->userRDFReader->getUserPassword($userName);
|
---|
63 | $encryptedPassword = $encryptedPasswordLiteral[0]['?password']->label;
|
---|
64 |
|
---|
65 | if(!strcmp($this->RIJNDAEL_encrypt($userPassword),$encryptedPassword))
|
---|
66 | $result = true;
|
---|
67 |
|
---|
68 | return $result;
|
---|
69 | }
|
---|
70 |
|
---|
71 | protected function RIJNDAEL_encrypt($text)
|
---|
72 | {
|
---|
73 | $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
|
---|
74 | $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
|
---|
75 |
|
---|
76 | return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this->key, $text, MCRYPT_MODE_ECB, $iv));
|
---|
77 | }
|
---|
78 | }
|
---|
79 |
|
---|
80 | ?> |
---|