source: Dev/trunk/classes/UserDatabaseInterface.php @ 94

Last change on this file since 94 was 83, checked in by basvannuland, 14 years ago

start with answer saving

File size: 2.1 KB
RevLine 
[44]1<?php
2
3// Survey class as intermediate for storing data from the site to the RDF database
4require_once 'rdfConstants.php';
5
6// Include RAP Library to write RDF files
7include(RDFAPI_INCLUDE_DIR . "RDFAPI.php");
8
9class UserDatabaseInterface
10{
[62]11    protected $key = 'CPSsecretKey';
[44]12
[62]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
[83]27        if(!$this->checkUserName($userName))
[82]28        {
29            $this->userRDFWriter->addNewUser($userName, $userPassword);
30            $this->userRDFWriter->saveUsers();           
31        }
[62]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            {
[83]44                $name = $user['?name']->label;
[62]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);
[82]63        $encryptedPassword = $encryptedPasswordLiteral[0]['?password']->label;
[62]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    }
[44]78}
79
80?>
Note: See TracBrowser for help on using the repository browser.