Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for wide characters in passwords. #2628

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/WeBWorK/Authen.pm
Original file line number Diff line number Diff line change
Expand Up @@ -633,8 +633,15 @@ sub checkPassword {
my $Password = $db->getPassword($userID);
if (defined $Password) {
# Check against the password in the database.
my $possibleCryptPassword = crypt $possibleClearPassword, $Password->password;
my $dbPassword = $Password->password;
my $possibleCryptPassword = '';
# Wrap crypt in an eval to catch any "Wide character in crypt" errors.
# If crypt fails due to a wide character, encode to UTF-8 before calling crypt.
eval { $possibleCryptPassword = crypt $possibleClearPassword, $Password->password; };
if ($@ && $@ =~ /Wide char/) {
$possibleCryptPassword = crypt Encode::encode_utf8($possibleClearPassword), $Password->password;
}

my $dbPassword = $Password->password;
# This next line explicitly insures that blank or null passwords from the database can never succeed in matching
# an entered password. This also rejects cases when the database has a crypted password which matches a
# submitted all white-space or null password by requiring that the $possibleClearPassword contain some non-space
Expand Down
11 changes: 10 additions & 1 deletion lib/WeBWorK/ContentGenerator/Options.pm
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,16 @@ sub initialize ($c) {
$userID ne $effectiveUserID ? eval { $db->getPassword($c->{effectiveUser}->user_id) } : $password;

# Check that either password is not defined or if it is defined then we have the right one.
if (!defined $password || crypt($currP // '', $password->password) eq $password->password) {
my $cryptedCurrP;
if (defined $password) {
# Wrap crypt in an eval to catch any "Wide character in crypt" errors.
# If crypt fails due to a wide character, encode to UTF-8 before calling crypt.
eval { $cryptedCurrP = crypt($currP // '', $password->password); };
if ($@ && $@ =~ /Wide char/) {
$cryptedCurrP = crypt(Encode::encode_utf8($currP), $password->password);
}
}
if (!defined $password || $cryptedCurrP eq $password->password) {
my $e_user_name = $c->{effectiveUser}->first_name . ' ' . $c->{effectiveUser}->last_name;
if ($newP eq $confirmP) {
if (!defined $effectiveUserPassword) {
Expand Down
10 changes: 9 additions & 1 deletion lib/WeBWorK/Utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,15 @@ sub cryptPassword ($clearPassword) {
$salt .= ('.', '/', '0' .. '9', 'A' .. 'Z', 'a' .. 'z')[ rand 64 ];
}

return crypt(trim_spaces($clearPassword), $salt);
# Wrap crypt in an eval to catch any "Wide character in crypt" errors.
# If crypt fails due to a wide character, encode to UTF-8 before calling crypt.
my $cryptedPassword = '';
eval { $cryptedPassword = crypt(trim_spaces($clearPassword), $salt); };
if ($@ && $@ =~ /Wide char/) {
$cryptedPassword = crypt(Encode::encode_utf8(trim_spaces($clearPassword)), $salt);
}

return $cryptedPassword;
}

sub undefstr ($default, @values) {
Expand Down