Skip to content

Commit

Permalink
Item12180: Encode wide characters in PASSWORDs
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk@16330 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
TimotheLitt authored and TimotheLitt committed Jan 3, 2013
1 parent 14dfde3 commit 6d1eb2f
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions core/lib/Foswiki/Configure/Types/PASSWORD.pm
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,27 @@ sub value2string {

$_[2] = '*' x 15;

my $txt = Data::Dumper->Dump( [ encode_base64( $value, '' ) ] );
use bytes();
my $txt;

# base64 is undefined for wide characters.
# If wide characters are present, Encode into octects first

if ( length($value) < bytes::length($value) ) {
require Encode;

$txt = Data::Dumper->Dump(
[ encode_base64( Encode::encode_utf8($value), '' ) ] );
$txt =~
s/VAR1\s+=\s+(.*?);\n/Foswiki::cfg$keys = Encode::decode_utf8(MIME::Base64::decode_base64($1));\n/ms;
return ( $txt, [qw/MIME::Base64 Encode/] );
}

# No wide characters, use simpler encoding

$txt = Data::Dumper->Dump( [ encode_base64( $value, '' ) ] );
$txt =~
s/VAR1\s+=\s+(.*?);\n/Foswiki::cfg$keys = MIME::Base64::decode_base64( $1 );\n/ms;
s/VAR1\s+=\s+(.*?);\n/Foswiki::cfg$keys = MIME::Base64::decode_base64($1);\n/ms;

return ( $txt, 'MIME::Base64' );
}
Expand Down

0 comments on commit 6d1eb2f

Please sign in to comment.