Skip to content

Commit

Permalink
Item13378: added selector for special encoding on .htpasswd file
Browse files Browse the repository at this point in the history
  • Loading branch information
Comment committed May 20, 2015
1 parent b9f8746 commit 5b752fc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
7 changes: 7 additions & 0 deletions core/lib/Foswiki.spec
Expand Up @@ -650,6 +650,13 @@ $Foswiki::cfg{MinPasswordLength} = 7;
# email addresses from an existing file.
$Foswiki::cfg{Htpasswd}{FileName} = '$Foswiki::cfg{DataDir}/.htpasswd';

# **STRING LABEL="Password File Character Encodingname" DISPLAY_IF="/htpasswd/i.test({PasswordManager})" CHECK="iff:'{PasswordManager}=~/htpasswd/i'"**
# Character encoding used in the password file. This will default to utf-8, which allows any unicode
# character to be used in usernames, passwords and email addresses. The only time you should change it
# is if you have an existing password file that uses a different encoding (and even then only if there
# is at least one character in that file that has a codepoint that would conflict with utf-8).
# $Foswiki::cfg{Htpasswd}{CharacterEncoding} = 'utf-8';

# **PATH LABEL="Password Lock-Filename" EXPERT DISPLAY_IF="/htpasswd/i.test({PasswordManager})" CHECK="iff:'{PasswordManager}=~/htpasswd/i'"**
# Path to the lockfile for the password file. This normally does not need
# to be changed; however if two Foswiki installations share and update a
Expand Down
9 changes: 5 additions & 4 deletions core/lib/Foswiki/Users/HtPasswdUser.pm
Expand Up @@ -289,7 +289,8 @@ sub _readPasswd {

local $/ = "\n";

open( $IN_FILE, '<:encoding(utf-8)', $Foswiki::cfg{Htpasswd}{FileName} )
my $enc = $Foswiki::cfg{Htpasswd}{CharacterEncoding} || 'utf-8';
open( $IN_FILE, "<:encoding($enc)", $Foswiki::cfg{Htpasswd}{FileName} )
|| throw Error::Simple(
$Foswiki::cfg{Htpasswd}{FileName} . ' open failed: ' . $! );
my $line = '';
Expand Down Expand Up @@ -467,8 +468,7 @@ sub _savePasswd {
unless ( -e "$Foswiki::cfg{Htpasswd}{FileName}" ) {

# Item4544: Document special format used in .htpasswd for email addresses
open( my $readme, '>:encoding(utf-8)',
"$Foswiki::cfg{Htpasswd}{FileName}.README" )
open( my $readme, '>', "$Foswiki::cfg{Htpasswd}{FileName}.README" )
or throw Error::Simple(
$Foswiki::cfg{Htpasswd}{FileName} . '.README open failed: ' . $! );

Expand All @@ -488,7 +488,8 @@ EoT
my $oldMask = umask(077); # Access only by owner
my $fh;

open( $fh, '>:encoding(utf-8)', $Foswiki::cfg{Htpasswd}{FileName} )
my $enc = $Foswiki::cfg{Htpasswd}{CharacterEncoding} || 'utf-8';
open( $fh, ">:encoding($enc)", $Foswiki::cfg{Htpasswd}{FileName} )
|| throw Error::Simple(
"$Foswiki::cfg{Htpasswd}{FileName} open failed: $!");
print $fh $content;
Expand Down

0 comments on commit 5b752fc

Please sign in to comment.