Frontend: Better way of generating session tokens
This commit is contained in:
parent
606b13470e
commit
1e7bea8e5f
@ -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;
|
||||
|
||||
|
@ -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];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user