PerlDancer / PerlDancer/Dancer2-Plugin-Auth-Extensible
Using unicode in passwords fails
Nobody has claimed this yet.
- Dominant language
- Perl
- Stars
- 10
- Forks
- 21
- PR merge metrics
- No merged PRs in 30d
Description
I'm not sure if that's the right place/way to fix it, but in one of my apps the users noticed that the application dies with a 500 (ERROR users provider threw error: Wide character in subroutine entry at .../local/lib/perl5/Crypt/SaltedHash.pm line 215.). Turns out that Crypt::SaltedHash doesn't like unicode strings very much, so I put together a little patch to make it work:
diff --git a/lib/Dancer2/Plugin/Auth/Extensible.pm b/lib/Dancer2/Plugin/Auth/Extensible.pm
index 718a9ad..330ff6f 100644
--- a/lib/Dancer2/Plugin/Auth/Extensible.pm
+++ b/lib/Dancer2/Plugin/Auth/Extensible.pm
@@ -8,6 +8,7 @@ use Carp;
use Dancer2::Core::Types qw(ArrayRef Bool HashRef Int Str);
use Dancer2::FileUtils qw(path);
use Dancer2::Template::Tiny;
+use Encode qw(encode);
use File::Share qw(dist_dir);
use HTTP::BrowserDetect;
use List::Util qw(first);
@@ -446,6 +447,8 @@ sub authenticate_user {
my ( $plugin, $username, $password, $realm ) = @_;
my ( @errors, $success, $auth_realm );
+ $password = encode('utf-8', $password);
+
$plugin->execute_plugin_hook( 'before_authenticate_user',
{ username => $username, password => $password, realm => $realm } );
@@ -827,6 +830,7 @@ sub user_password {
}
if ( exists $params{password} ) {
my $success;
+ my $password = encode('utf-8', $params{password});
# Possible that realm will not be set before this statement
( $success, $realm ) =
@@ -848,6 +852,7 @@ sub user_password {
return unless $realm; # Invalid user
}
my $provider = $plugin->auth_provider($realm);
+ $new_password = encode('utf-8', $new_password);
$provider->set_user_password( $username, $new_password );
if ( $params{code} ) {
Again, not sure if it's the kind of fix you're looking for, but it solved the problem for me :) Is there a better way to do it, or is it indeed a bug in DPAE?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in lib/Dancer2/Plugin/Auth/Extensible.pm, especially authenticate_user and user_password, and trace how passwords reach the authentication provider. Check the existing password handling and verify that setting and authenticating with Unicode passwords no longer produces the reported 500 error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- perl
- Domain
- authentication
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100