diff --git a/frontend_routes.pm b/frontend_routes.pm index 9315837..fb54c34 100644 --- a/frontend_routes.pm +++ b/frontend_routes.pm @@ -20,7 +20,6 @@ use lib "."; use frontend_session; use Digest::SHA; -use Data::Dumper; use feature qw(switch); use strict; @@ -106,7 +105,7 @@ sub handlePath { return 1; } - my $token = Digest::SHA::sha256_hex(sprintf("%x", rand(0xFFFFFFFF)%0xFF)); + my $token = frontend_session::newSessionToken(); $frontend_session::sessions{$token}{"username"} = $username; $frontend_session::sessions{$token}{"logged"} = 1; diff --git a/frontend_session.pm b/frontend_session.pm index 25dd4ad..eade03d 100644 --- a/frontend_session.pm +++ b/frontend_session.pm @@ -16,11 +16,17 @@ package frontend_session; +use Digest::SHA; + use strict; use warnings; our %sessions; +sub newSessionToken { + return Digest::SHA::sha256_hex(sprintf("%x", rand(0xFFFFFFFF))); +} + sub isValidSession { my $aSession = $_[0];