1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the tiqr project. |
4
|
|
|
* |
5
|
|
|
* The tiqr project aims to provide an open implementation for |
6
|
|
|
* authentication using mobile devices. It was initiated by |
7
|
|
|
* SURFnet and developed by Egeniq. |
8
|
|
|
* |
9
|
|
|
* More information: http://www.tiqr.org |
10
|
|
|
* |
11
|
|
|
* @author Ivo Jansch <[email protected]> |
12
|
|
|
* |
13
|
|
|
* @package tiqr |
14
|
|
|
* |
15
|
|
|
* @license New BSD License - See LICENSE file for details. |
16
|
|
|
* |
17
|
|
|
* @copyright (C) 2010-2012 SURFnet BV |
18
|
|
|
*/ |
19
|
|
|
|
20
|
1 |
|
require_once 'Tiqr/UserStorage/File.php'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* This user storage implementation implements a simple user's secret storage using json files. |
24
|
|
|
* This is mostly for demonstration and development purposes. In a production environment |
25
|
|
|
* please supply your own implementation that hosts the data in your user database OR |
26
|
|
|
* in a secure (e.g. hardware encrypted) storage. |
27
|
|
|
* @author ivo |
28
|
|
|
*/ |
29
|
|
|
class Tiqr_UserSecretStorage_File extends Tiqr_UserStorage_File implements Tiqr_UserSecretStorage_Interface |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* Create an instance |
33
|
|
|
* |
34
|
|
|
* @param array $config |
35
|
|
|
*/ |
36
|
1 |
|
public function __construct($config, $secretconfig = array()) |
37
|
|
|
{ |
38
|
1 |
|
$this->_path = $config["path"]; |
39
|
1 |
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Get the user's secret |
43
|
|
|
* |
44
|
|
|
* @param String $userId |
45
|
|
|
* |
46
|
|
|
* @return String The user's secret |
47
|
|
|
*/ |
48
|
1 |
|
public function getUserSecret($userId) |
49
|
|
|
{ |
50
|
1 |
|
if ($data = $this->_loadUser($userId)) { |
51
|
1 |
|
if (isset($data["secret"])) { |
52
|
1 |
|
return $data["secret"]; |
53
|
|
|
} |
54
|
|
|
} |
55
|
1 |
|
return NULL; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Store a secret for a user |
60
|
|
|
* |
61
|
|
|
* @param String $userId |
62
|
|
|
* @param String $secret |
63
|
|
|
*/ |
64
|
1 |
|
public function setUserSecret($userId, $secret) |
65
|
|
|
{ |
66
|
1 |
|
$data = $this->_loadUser($userId, false); |
67
|
1 |
|
$data["secret"] = $secret; |
68
|
1 |
|
$this->_saveUser($userId, $data); |
|
|
|
|
69
|
1 |
|
} |
70
|
|
|
} |
71
|
|
|
|