diff --git a/installer/data/mysql/atomicupdate/bug_22030_add_OverDriveUsername_system_preference.perl b/installer/data/mysql/atomicupdate/bug_22030_add_OverDriveUsername_system_preference.perl
new file mode 100644
index 0000000000..73047781ac
--- /dev/null
+++ b/installer/data/mysql/atomicupdate/bug_22030_add_OverDriveUsername_system_preference.perl
@@ -0,0 +1,9 @@
+$DBversion = 'XXX';
+if( CheckVersion( $DBversion ) ) {
+ $dbh->do(q{
+ INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
+ ('OverDriveUsername','cardnumber','cardnumber|userid','Which patron information should be passed as OverDrive username','Choice')
+ });
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug XXXXX - description)\n";
+}
diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql
index 1e36c306c6..072ca5bb6a 100644
--- a/installer/data/mysql/sysprefs.sql
+++ b/installer/data/mysql/sysprefs.sql
@@ -431,6 +431,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `
('OverDriveClientSecret','','Client key for OverDrive integration','30','YesNo'),
('OverDriveLibraryID','','Library ID for OverDrive integration','','Integer'),
('OverDrivePasswordRequired','',NULL,'Does the library require passwords for OverDrive SIP authentication','YesNo'),
+('OverDriveUsername','cardnumber','cardnumber|userid','Which patron information should be passed as OverDrive username','Choice'),
('OverdueNoticeCalendar',0,NULL,'Take the calendar into consideration when generating overdue notices','YesNo'),
('OverduesBlockCirc','noblock','noblock|confirmation|block','When checking out an item should overdues block checkout, generate a confirmation dialogue, or allow checkout','Choice'),
('OverduesBlockRenewing','allow','allow|blockitem|block','If any of patron checked out documents is late, should renewal be allowed, blocked only on overdue items or blocked on whatever checked out document','Choice'),
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/enhanced_content.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/enhanced_content.pref
index 67db1fbb01..f6e01e2ea2 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/enhanced_content.pref
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/enhanced_content.pref
@@ -384,6 +384,12 @@ Enhanced Content:
yes: Enable
no: "Don't enable"
- users to access their OverDrive circulation history, and circulate items.
+ - Overdrive uses the patron's
+ - pref: OverDriveUsername
+ choices:
+ cardnumber: cardnumber
+ userid: user name
+ - for user access to OverDrive.
- A password is
- pref: OverDrivePasswordRequired
choices:
diff --git a/opac/svc/overdrive b/opac/svc/overdrive
index 3ede3f4fdb..57333f0066 100755
--- a/opac/svc/overdrive
+++ b/opac/svc/overdrive
@@ -48,9 +48,15 @@ eval {
my $password = $cgi->param("password") // q{} ;
my $patron = Koha::Patrons->find({ userid => $user });
my $branch_info = $patron ? Koha::Library::OverDriveInfos->find( $patron->branchcode ) : undef;
+ my $od_username;
+ if ( C4::Context->preference('OverDriveUsername') eq 'cardnumber' ){
+ $od_username = $patron ? $patron->cardnumber : undef;
+ } else {
+ $od_username = $user;
+ }
my $branch_authname = $branch_info ? $branch_info->authname : undef;
my $authname = $branch_authname || C4::Context->preference('OverDriveAuthname');
- $od->auth_by_userid($user, $password,C4::Context->preference('OverDriveWebsiteID'),$authname);
+ $od->auth_by_userid($od_username, $password,C4::Context->preference('OverDriveWebsiteID'),$authname);
$data{login_success} = 1;
last;
};