Koha/installer/data/mysql/db_revs/210600026.pl
Jonathan Druart 1e9c2afbb3 Bug 28772: DBRev 21.06.00.026
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2021-09-30 09:49:50 +02:00

34 lines
868 B
Perl
Executable file

use Modern::Perl;
return {
bug_number => "28772",
description => "Store hashed API key secrets",
up => sub {
my ($args) = @_;
my ($dbh) = @$args{qw(dbh)};
use Koha::AuthUtils qw(hash_password);
my $sth = $dbh->prepare(q{
SELECT client_id, secret
FROM api_keys
});
$sth->execute;
my $results = $sth->fetchall_arrayref({});
$sth = $dbh->prepare(q{
UPDATE api_keys
SET
secret = ?
WHERE
client_id = ?
});
foreach my $api_key (@$results) {
unless ( $api_key->{secret} =~ m/^\$2a\$08\$/ ) {
my $digest = Koha::AuthUtils::hash_password( $api_key->{secret} );
$sth->execute( $digest, $api_key->{client_id} );
}
}
},
}