Frontend: Better way of generating session tokens

This commit is contained in:
mrkubax10 2023-09-09 10:52:28 +02:00
parent 606b13470e
commit 1e7bea8e5f
2 changed files with 7 additions and 2 deletions

View File

@ -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;

View File

@ -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];