Fix ENV_HASH not working correctly.

This commit is contained in:
2025-06-23 15:01:12 +03:00
parent 94d377c0c2
commit ac99cef842
4 changed files with 11 additions and 6 deletions

1
.gitignore vendored
View File

@@ -2,3 +2,4 @@
tmp.*
*.log
.env
p.vim

13
main.rb
View File

@@ -7,18 +7,20 @@ require "uri"
require "xxhash"
require "zlib"
load "logman.rb"
ALPHANUM = [*"0".."9", *"A".."Z", *"a".."z", "-", "_"].freeze
env_data = File.read(".env")
ENV_HASH = {}
env_data.each_line do |line|
if (match = line.match(/^([A-Z_][A-Z0-9_]*)=(.*)$/))
_, key, val = match
ENV_HASH[key] = val
end
next unless (match = line.match(/^([A-Z_][A-Z0-9_]*)=(.*)$/))
ENV_HASH[match[1]] = match[2]
end
Logman.log ENV_HASH.inspect
CODE_ENV = :dev
db_file = File.expand_path("infinsweeper.db")
@@ -26,7 +28,6 @@ DB = Sequel.connect("sqlite:///#{db_file}", single_threaded: false)
DB.run("PRAGMA foreign_keys = ON;")
$active_users = DB[:SignedInUsers].all.map { |x| [x[:code], x[:player]] }.to_h
load "logman.rb"
load "mailer.rb"
load "players.rb"
load "session.rb"
@@ -35,7 +36,7 @@ set :public_folder, "public"
get "/" do
session = Sessions.new request, response
Logman.log session["message"]
Logman.log session["message"].inspect
send_file "index.html"
end

View File

@@ -64,6 +64,7 @@ module Players
def self.authorized?(username, pass)
digest = XXhash.xxh32(pass, ENV_HASH["SALT"])
Logman.log "Authorized: #{username} & #{digest}\n"
player = self[username]
player && player[:digest].to_i == digest.to_i ? player : false
end

View File

@@ -20,6 +20,8 @@ class Sessions
end
def login(username, pass)
Logman.log "Logging in: #{username} & #{pass} #{ENV_HASH["SALT"]}\n"
player = Players.authorized?(username, pass)
if player
code = Array.new(24) { ALPHANUM.sample }.join