diff options
author | dakkar <dakkar@thenautilus.net> | 2017-12-16 18:00:36 +0000 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2017-12-16 18:00:36 +0000 |
commit | 6a3b3f916eee0d757bd52a690bc398fe01a1dc9c (patch) | |
tree | f0a69eaa9553e4c2ff7cbe0be9e9a7fe0e0ee389 /lib/Ultramarine | |
parent | ignore file (diff) | |
download | Ultramarine-6a3b3f916eee0d757bd52a690bc398fe01a1dc9c.tar.gz Ultramarine-6a3b3f916eee0d757bd52a690bc398fe01a1dc9c.tar.bz2 Ultramarine-6a3b3f916eee0d757bd52a690bc398fe01a1dc9c.zip |
users model
Diffstat (limited to 'lib/Ultramarine')
-rw-r--r-- | lib/Ultramarine/Model/Users.pm6 | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/Ultramarine/Model/Users.pm6 b/lib/Ultramarine/Model/Users.pm6 new file mode 100644 index 0000000..ad52ab4 --- /dev/null +++ b/lib/Ultramarine/Model/Users.pm6 @@ -0,0 +1,25 @@ +use v6.d.PREVIEW; +use Digest::MD5; +use experimental :pack; + +class Ultramarine::Model::Users { + has %!accounts; + + submethod BUILD(:%!accounts) {} + + multi method authenticate(:$user!,:$password! is copy) { + $password ~~ s[^enc\:(.+)$] = pack('H*',$/[0]).decode('UTF-8'); + + return (%!accounts{$user} && %!accounts{$user} eq $password); + } + + multi method authenticate(:$user!,:$token!,:$salt!) { + return unless my $password = %!accounts{$user}; + + my $expected_token = Digest::MD5.md5_hex( + $password ~ $salt + ); + + return $token eq $expected_token; + } +} |