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

Last change on this file since 69 was 62, checked in by basvannuland, 14 years ago

updates to the database system. ao New file structure

File size: 2.1 KB
Line 
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{
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        $this->userRDFWriter->addNewUser($userName, $userPassword);
28        $this->userRDFWriter->saveUsers();
29    }
30
31    public function checkUserName($userName)
32    {
33        $result = false;
34
35        $resultUser = $this->userRDFReader->getUserNames();
36
37        if ($resultUser != null)
38        {
39            foreach($resultUser as $user)
40            {
41            $name = substr($user['?name'],9,strlen($user['?name'])-11);
42                if(!strcmp($name ,$userName))
43                {
44                    $result = true;
45                }
46            }
47        }
48
49        return $result;
50    }
51
52    public function checkUserPassword($userInfo)
53    {
54        $result = false;
55
56        $userName = $userInfo['username'];
57        $userPassword = $userInfo['password'];
58
59        $encryptedPasswordLiteral = $this->userRDFReader->getUserPassword($userName);
60        $encryptedPassword = substr($encryptedPasswordLiteral[0]['?password'],9,strlen($encryptedPasswordLiteral[0]['?password'])-11);
61
62        if(!strcmp($this->RIJNDAEL_encrypt($userPassword),$encryptedPassword))
63            $result = true;
64
65        return $result;
66    }
67
68    protected function RIJNDAEL_encrypt($text)
69    {
70        $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
71        $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
72
73        return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this->key, $text, MCRYPT_MODE_ECB, $iv));
74    }
75}
76
77?>
Note: See TracBrowser for help on using the repository browser.