summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2009-07-31 12:50:31 +0200
committerYorhel <git@yorhel.nl>2009-07-31 12:50:31 +0200
commitaf5293b8d33f4948ee5c9bcc2c4df38e611c88c6 (patch)
tree7f530f9df07bbfb893c74e406f127237b89b316b
parent5e9e6a78d3b7ffd177d91dba6602946dbd9a4c09 (diff)
Use bytea data type to store session tokens
To be consistent with users.passwd - hashes are stored in binary. All conversion from/to hex is done in the DB layer.
-rw-r--r--lib/VNDB/DB/Users.pm18
-rw-r--r--util/dump.sql2
-rw-r--r--util/updates/update_2.6.sql2
3 files changed, 10 insertions, 12 deletions
diff --git a/lib/VNDB/DB/Users.pm b/lib/VNDB/DB/Users.pm
index ae46b896..a0e204e8 100644
--- a/lib/VNDB/DB/Users.pm
+++ b/lib/VNDB/DB/Users.pm
@@ -117,10 +117,10 @@ sub dbUserDel {
sub dbSessionAdd {
my($s, @o) = @_;
if (defined $o[2]) {
- $s->dbExec(q|INSERT INTO sessions (uid, token, expiration) VALUES(?, ?, ?)|,
+ $s->dbExec(q|INSERT INTO sessions (uid, token, expiration) VALUES(?, decode(?, 'hex'), ?)|,
@o);
} else {
- $s->dbExec(q|INSERT INTO sessions (uid, token) VALUES(?, ?)|,
+ $s->dbExec(q|INSERT INTO sessions (uid, token) VALUES(?, decode(?, 'hex'))|,
@o);
}
}
@@ -131,13 +131,9 @@ sub dbSessionAdd {
# uid, token (optional)
sub dbSessionDel {
my($s, @o) = @_;
- if (defined $o[1]) {
- $s->dbExec(q|DELETE FROM sessions WHERE uid = ? AND token = ?|,
- @o[0..1]);
- } else {
- $s->dbExec(q|DELETE FROM sessions WHERE uid = ?|,
- $o[0]);
- }
+ my %where = ('uid = ?' => $o[0]);
+ $where{"token = decode(?, 'hex')"} = $o[1] if $o[1];
+ $s->dbExec('DELETE FROM sessions !W', \%where);
}
@@ -146,7 +142,9 @@ sub dbSessionDel {
# uid, token
sub dbSessionCheck {
my($s, @o) = @_;
- return $s->dbRow(q|SELECT count(uid) AS count FROM sessions WHERE uid = ? AND token = ? LIMIT 1|, @o)->{count}||0;
+ return $s->dbRow(
+ q|SELECT count(uid) AS count FROM sessions WHERE uid = ? AND token = decode(?, 'hex') LIMIT 1|, @o
+ )->{count}||0;
}
diff --git a/util/dump.sql b/util/dump.sql
index 2bb4fda5..ea5d7e68 100644
--- a/util/dump.sql
+++ b/util/dump.sql
@@ -164,7 +164,7 @@ CREATE TABLE screenshots (
-- sessions
CREATE TABLE sessions (
uid integer NOT NULL,
- token character(40) NOT NULL,
+ token bytea NOT NULL,
expiration timestamp NOT NULL DEFAULT (now() + '1 year'::interval),
PRIMARY KEY (uid, token)
);
diff --git a/util/updates/update_2.6.sql b/util/updates/update_2.6.sql
index 79fefd69..f0ddff65 100644
--- a/util/updates/update_2.6.sql
+++ b/util/updates/update_2.6.sql
@@ -3,7 +3,7 @@
-- Create table for session data storage
CREATE TABLE sessions (
uid integer NOT NULL REFERENCES users(id),
- token character(40) NOT NULL,
+ token bytea NOT NULL,
expiration timestamp NOT NULL DEFAULT (NOW() + '1 year'::interval),
PRIMARY KEY (uid, token)
);