-my ($borr, $flags) = getpatroninformation(undef, $borrowernumber);
-my $sth = $dbh->prepare("UPDATE borrowers SET password = ? WHERE borrowernumber=?");
-
-if ( $query->param('Oldkey') && $query->param('Newkey') && $query->param('Confirm') ){
- if ( goodkey($dbh,$borrowernumber, $query->param('Oldkey')) ){
- if ( $query->param('Newkey') eq $query->param('Confirm') &&
- length($query->param('Confirm')) > 5 ){ # Record password
- my $clave = md5_base64($query->param('Newkey'));
- $sth->execute($clave,$borrowernumber);
- $template->param('password_updated' => '1');
- $template->param('borrowernumber' => $borrowernumber);
- }elsif ( $query->param('Newkey') ne $query->param('Confirm') ){
- $template->param('Ask_data' => '1');
- $template->param('Error_messages' => '1');
- $template->param('PassMismatch' => '1');
- }elsif (length($query->param('Confirm')) <= 5 ){
- $template->param('Ask_data' => '1');
- $template->param('Error_messages' => '1');
- $template->param('ShortPass' => '1');
- }else{
- $template->param('Error_messages' => '1');
- }
- }else{
- $template->param('Ask_data' => '1');
- $template->param('Error_messages' => '1');
- $template->param('WrongPass' => '1');
+my ( $borr ) = GetMemberDetails( $borrowernumber );
+my $sth = $dbh->prepare("UPDATE borrowers SET password = ? WHERE borrowernumber=?");
+my $minpasslen = C4::Context->preference("minPasswordLength");
+if ( $query->param('Oldkey')
+ && $query->param('Newkey')
+ && $query->param('Confirm') )
+{
+ if ( goodkey( $dbh, $borrowernumber, $query->param('Oldkey') ) ) {
+ if ( $query->param('Newkey') eq $query->param('Confirm')
+ && length( $query->param('Confirm') ) >= $minpasslen )
+ { # Record password
+ my $clave = md5_base64( $query->param('Newkey') );
+ $sth->execute( $clave, $borrowernumber );
+ $template->param( 'password_updated' => '1' );
+ $template->param( 'borrowernumber' => $borrowernumber );
+ }
+ elsif ( $query->param('Newkey') ne $query->param('Confirm') ) {
+ $template->param( 'Ask_data' => '1' );
+ $template->param( 'Error_messages' => '1' );
+ $template->param( 'PassMismatch' => '1' );
+ }
+ elsif ( length( $query->param('Confirm') ) < $minpasslen ) {
+ $template->param( 'Ask_data' => '1' );
+ $template->param( 'Error_messages' => '1' );
+ $template->param( 'ShortPass' => '1' );
+ }
+ else {
+ $template->param( 'Error_messages' => '1' );
+ }
+ }
+ else {
+ $template->param( 'Ask_data' => '1' );
+ $template->param( 'Error_messages' => '1' );
+ $template->param( 'WrongPass' => '1' );
+ }
+}
+else {
+
+ # Called Empty, Ask for data.
+ $template->param( 'Ask_data' => '1' );
+ if (!$query->param('Oldkey') && ($query->param('Newkey') || $query->param('Confirm'))){
+ # Old password is empty but one of the others isnt
+ $template->param( 'Error_messages' => '1' );
+ $template->param( 'WrongPass' => '1' );
+ }
+ elsif ($query->param('Oldkey') && (!$query->param('Newkey') || !$query->param('Confirm'))){
+ # Oldpassword is entered but one of the other fields is empty
+ $template->param( 'Error_messages' => '1' );
+ $template->param( 'PassMismatch' => '1' );