diff options
author | Melanie | 2009-09-04 07:48:09 +0100 |
---|---|---|
committer | Melanie | 2009-09-04 07:48:09 +0100 |
commit | ac40c7a74c15e0f61ba5bfcb4c6a6fb39993a87c (patch) | |
tree | cc15d7ddc6423775d14b7d829400e6cf14e730e5 /OpenSim/Data/MySQL/MySQLAuthenticationData.cs | |
parent | Merge branch 'master' of ssh://melanie@opensimulator.org/var/git/opensim (diff) | |
download | opensim-SC_OLD-ac40c7a74c15e0f61ba5bfcb4c6a6fb39993a87c.zip opensim-SC_OLD-ac40c7a74c15e0f61ba5bfcb4c6a6fb39993a87c.tar.gz opensim-SC_OLD-ac40c7a74c15e0f61ba5bfcb4c6a6fb39993a87c.tar.bz2 opensim-SC_OLD-ac40c7a74c15e0f61ba5bfcb4c6a6fb39993a87c.tar.xz |
Fully implement unencrypted auth token operations
Diffstat (limited to 'OpenSim/Data/MySQL/MySQLAuthenticationData.cs')
-rw-r--r-- | OpenSim/Data/MySQL/MySQLAuthenticationData.cs | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/OpenSim/Data/MySQL/MySQLAuthenticationData.cs b/OpenSim/Data/MySQL/MySQLAuthenticationData.cs index 19575ec..1ee64ce 100644 --- a/OpenSim/Data/MySQL/MySQLAuthenticationData.cs +++ b/OpenSim/Data/MySQL/MySQLAuthenticationData.cs | |||
@@ -39,6 +39,7 @@ namespace OpenSim.Data.MySQL | |||
39 | { | 39 | { |
40 | private string m_Realm; | 40 | private string m_Realm; |
41 | private List<string> m_ColumnNames = null; | 41 | private List<string> m_ColumnNames = null; |
42 | private int m_LastExpire = 0; | ||
42 | 43 | ||
43 | public MySqlAuthenticationData(string connectionString, string realm) | 44 | public MySqlAuthenticationData(string connectionString, string realm) |
44 | : base(connectionString) | 45 | : base(connectionString) |
@@ -153,5 +154,56 @@ namespace OpenSim.Data.MySQL | |||
153 | 154 | ||
154 | return false; | 155 | return false; |
155 | } | 156 | } |
157 | |||
158 | public bool SetToken(UUID principalID, string token, int lifetime) | ||
159 | { | ||
160 | if (System.Environment.TickCount - m_LastExpire > 30000) | ||
161 | DoExpire(); | ||
162 | |||
163 | MySqlCommand cmd = new MySqlCommand("insert into tokens (UUID, token, validity) values (?principalID, ?token, date_add(now(), interval ?lifetime minute))"); | ||
164 | cmd.Parameters.AddWithValue("?principalID", principalID.ToString()); | ||
165 | cmd.Parameters.AddWithValue("?token", token); | ||
166 | cmd.Parameters.AddWithValue("?lifetime", lifetime.ToString()); | ||
167 | |||
168 | if (ExecuteNonQuery(cmd) > 0) | ||
169 | { | ||
170 | cmd.Dispose(); | ||
171 | return true; | ||
172 | } | ||
173 | |||
174 | cmd.Dispose(); | ||
175 | return false; | ||
176 | } | ||
177 | |||
178 | public bool CheckToken(UUID principalID, string token, int lifetime) | ||
179 | { | ||
180 | if (System.Environment.TickCount - m_LastExpire > 30000) | ||
181 | DoExpire(); | ||
182 | |||
183 | MySqlCommand cmd = new MySqlCommand("update tokens set validity = date_add(now(), interval ?lifetime minute) where UUID = ?principalID and token = ?token and validity > now()"); | ||
184 | cmd.Parameters.AddWithValue("?principalID", principalID.ToString()); | ||
185 | cmd.Parameters.AddWithValue("?token", token); | ||
186 | cmd.Parameters.AddWithValue("?lifetime", lifetime.ToString()); | ||
187 | |||
188 | if (ExecuteNonQuery(cmd) > 0) | ||
189 | { | ||
190 | cmd.Dispose(); | ||
191 | return true; | ||
192 | } | ||
193 | |||
194 | cmd.Dispose(); | ||
195 | |||
196 | return false; | ||
197 | } | ||
198 | |||
199 | private void DoExpire() | ||
200 | { | ||
201 | MySqlCommand cmd = new MySqlCommand("delete from tokens where validity < now()"); | ||
202 | ExecuteNonQuery(cmd); | ||
203 | |||
204 | cmd.Dispose(); | ||
205 | |||
206 | m_LastExpire = System.Environment.TickCount; | ||
207 | } | ||
156 | } | 208 | } |
157 | } | 209 | } |