summaryrefslogtreecommitdiff
path: root/lib/Ultramarine/Model/Users.pm6
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Ultramarine/Model/Users.pm6')
-rw-r--r--lib/Ultramarine/Model/Users.pm625
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;
+ }
+}