Rev 253 | Rev 264 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 253 | Rev 261 | ||
---|---|---|---|
Line 29... | Line 29... | ||
29 | public function raEmail() { |
29 | public function raEmail() { |
30 | return $this->email; |
30 | return $this->email; |
31 | } |
31 | } |
32 | 32 | ||
33 | public function existing() { |
33 | public function existing() { |
34 | $res = OIDplus::db()->query("select email from ".OIDPLUS_TABLENAME_PREFIX."ra where email = ?", array($this->email)); |
34 | $res = OIDplus::db()->query("select email from ###ra where email = ?", array($this->email)); |
35 | return ($res->num_rows() > 0); |
35 | return ($res->num_rows() > 0); |
36 | } |
36 | } |
37 | 37 | ||
38 | public function raName() { |
38 | public function raName() { |
39 | $res = OIDplus::db()->query("select ra_name from ".OIDPLUS_TABLENAME_PREFIX."ra where email = ?", array($this->email)); |
39 | $res = OIDplus::db()->query("select ra_name from ###ra where email = ?", array($this->email)); |
40 | if ($res->num_rows() == 0) return "(RA not in database)"; |
40 | if ($res->num_rows() == 0) return "(RA not in database)"; |
41 | $row = $res->fetch_array(); |
41 | $row = $res->fetch_array(); |
42 | return $row['ra_name']; |
42 | return $row['ra_name']; |
43 | } |
43 | } |
44 | 44 | ||
45 | public static function getAllRAs() { |
45 | public static function getAllRAs() { |
46 | $out = array(); |
46 | $out = array(); |
47 | $res = OIDplus::db()->query("select email from ".OIDPLUS_TABLENAME_PREFIX."ra"); |
47 | $res = OIDplus::db()->query("select email from ###ra"); |
48 | while ($row = $res->fetch_array()) { |
48 | while ($row = $res->fetch_array()) { |
49 | $out[] = new OIDplusRA($row['email']); |
49 | $out[] = new OIDplusRA($row['email']); |
50 | } |
50 | } |
51 | return $out; |
51 | return $out; |
52 | } |
52 | } |
53 | 53 | ||
54 | public function change_password($new_password) { |
54 | public function change_password($new_password) { |
55 | $s_salt = substr(md5(rand()), 0, 7); |
55 | $s_salt = substr(md5(rand()), 0, 7); |
56 | $calc_authkey = 'A2#'.base64_encode(version_compare(PHP_VERSION, '7.1.0') >= 0 ? hash('sha3-512', $s_salt.$new_password, true) : bb\Sha3\Sha3::hash($s_salt.$new_password, 512, true)); |
56 | $calc_authkey = 'A2#'.base64_encode(version_compare(PHP_VERSION, '7.1.0') >= 0 ? hash('sha3-512', $s_salt.$new_password, true) : bb\Sha3\Sha3::hash($s_salt.$new_password, 512, true)); |
57 | OIDplus::db()->query("update ".OIDPLUS_TABLENAME_PREFIX."ra set salt=?, authkey=? where email = ?", array($s_salt, $calc_authkey, $this->email)); |
57 | OIDplus::db()->query("update ###ra set salt=?, authkey=? where email = ?", array($s_salt, $calc_authkey, $this->email)); |
58 | } |
58 | } |
59 | 59 | ||
60 | public function change_email($new_email) { |
60 | public function change_email($new_email) { |
61 | OIDplus::db()->query("update ".OIDPLUS_TABLENAME_PREFIX."ra set email = ? where email = ?", array($new_email, $this->email)); |
61 | OIDplus::db()->query("update ###ra set email = ? where email = ?", array($new_email, $this->email)); |
62 | } |
62 | } |
63 | 63 | ||
64 | public function register_ra($new_password) { |
64 | public function register_ra($new_password) { |
65 | $s_salt = substr(md5(rand()), 0, 7); |
65 | $s_salt = substr(md5(rand()), 0, 7); |
66 | $calc_authkey = 'A2#'.base64_encode(version_compare(PHP_VERSION, '7.1.0') >= 0 ? hash('sha3-512', $s_salt.$new_password, true) : bb\Sha3\Sha3::hash($s_salt.$new_password, 512, true)); |
66 | $calc_authkey = 'A2#'.base64_encode(version_compare(PHP_VERSION, '7.1.0') >= 0 ? hash('sha3-512', $s_salt.$new_password, true) : bb\Sha3\Sha3::hash($s_salt.$new_password, 512, true)); |
67 | if (OIDplus::db()->slang() == 'mssql') { |
67 | if (OIDplus::db()->slang() == 'mssql') { |
68 | OIDplus::db()->query("insert into ".OIDPLUS_TABLENAME_PREFIX."ra (salt, authkey, email, registered) values (?, ?, ?, getdate())", array($s_salt, $calc_authkey, $this->email)); |
68 | OIDplus::db()->query("insert into ###ra (salt, authkey, email, registered) values (?, ?, ?, getdate())", array($s_salt, $calc_authkey, $this->email)); |
69 | } else { |
69 | } else { |
70 | // MySQL + PgSQL |
70 | // MySQL + PgSQL |
71 | OIDplus::db()->query("insert into ".OIDPLUS_TABLENAME_PREFIX."ra (salt, authkey, email, registered) values (?, ?, ?, now())", array($s_salt, $calc_authkey, $this->email)); |
71 | OIDplus::db()->query("insert into ###ra (salt, authkey, email, registered) values (?, ?, ?, now())", array($s_salt, $calc_authkey, $this->email)); |
72 | } |
72 | } |
73 | } |
73 | } |
74 | 74 | ||
75 | public function checkPassword($password) { |
75 | public function checkPassword($password) { |
76 | $ra_res = OIDplus::db()->query("select authkey, salt from ".OIDPLUS_TABLENAME_PREFIX."ra where email = ?", array($this->email)); |
76 | $ra_res = OIDplus::db()->query("select authkey, salt from ###ra where email = ?", array($this->email)); |
77 | if ($ra_res->num_rows() == 0) return false; // User not found |
77 | if ($ra_res->num_rows() == 0) return false; // User not found |
78 | $ra_row = $ra_res->fetch_array(); |
78 | $ra_row = $ra_res->fetch_array(); |
79 | 79 | ||
80 | $plugins = OIDplus::getAuthPlugins(); |
80 | $plugins = OIDplus::getAuthPlugins(); |
81 | if (count($plugins) == 0) { |
81 | if (count($plugins) == 0) { |
Line 87... | Line 87... | ||
87 | 87 | ||
88 | return false; |
88 | return false; |
89 | } |
89 | } |
90 | 90 | ||
91 | public function delete() { |
91 | public function delete() { |
92 | OIDplus::db()->query("delete from ".OIDPLUS_TABLENAME_PREFIX."ra where email = ?", array($this->email)); |
92 | OIDplus::db()->query("delete from ###ra where email = ?", array($this->email)); |
93 | } |
93 | } |
94 | 94 | ||
95 | public function setRaName($ra_name) { |
95 | public function setRaName($ra_name) { |
96 | OIDplus::db()->query("update ".OIDPLUS_TABLENAME_PREFIX."ra set ra_name = ? where email = ?", array($ra_name, $this->email)); |
96 | OIDplus::db()->query("update ###ra set ra_name = ? where email = ?", array($ra_name, $this->email)); |
97 | } |
97 | } |
98 | } |
98 | } |