summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rwxr-xr-xlib/rddb.pm31
1 files changed, 24 insertions, 7 deletions
diff --git a/lib/rddb.pm b/lib/rddb.pm
index a7506a2..c12ea26 100755
--- a/lib/rddb.pm
+++ b/lib/rddb.pm
@@ -32,12 +32,7 @@ sub closedb
sub get_token
{
- my $username = shift;
-
- my ($dbh, $state, $errorstring) = opendb();
- unless(defined $dbh) {
- return ('', $state, $errorstring);
- }
+ my ($dbh, $username) = @_;
my $sth = $dbh->prepare('select PASSWORD from USERS where LOGIN_NAME = ?')
or return ('', 'ERROR', "Database Error: " . $dbh->errstr);
@@ -47,7 +42,6 @@ sub get_token
my ($token) = $sth->fetchrow_array;
$sth->finish();
- closedb($dbh);
unless(defined $token) {
return ('', 'ERROR', "user '" . $username . "' not known by rivendell")
@@ -55,4 +49,27 @@ sub get_token
return ($token, 'OK', 'success');
}
+sub check_token
+{
+ my ($dbh, $username, $token) = @_;
+
+ my $sth = $dbh->prepare('select PASSWORD from USERS where LOGIN_NAME = ?')
+ or return (0, 'ERROR', "Database Error: " . $dbh->errstr);
+
+ $sth->execute($username)
+ or return (0, 'ERROR', "Database Error: " . $sth->errstr);
+
+ my ($token_result) = $sth->fetchrow_array;
+ $sth->finish();
+
+ unless(defined $token_result) {
+ return (0, 'ERROR', "user '" . $username . "' not known by rivendell")
+ }
+
+ if($token_result == $token) {
+ return (1, 'OK', 'success');
+ }
+ return (0, 'ERROR', "wrong password");
+}
+
return 1;