iteration

This commit is contained in:
2023-10-09 06:54:35 -04:00
parent e6ed55bcc7
commit bb0d27b755
9 changed files with 515 additions and 77 deletions

View File

@@ -1,4 +1,9 @@
settings.define("auth_server.salt", {
description = "Salt for hashing passwords",
type = "string",
default = "3m&LmNm7"
})
local data = {
users = {}
@@ -7,6 +12,7 @@ local data = {
-- data = {
-- users = {
-- ["username"] = {
-- token = "token",
-- password = "hashed password",
-- groups = {
-- ["group"] = true
@@ -31,28 +37,15 @@ function load_data()
end
function generate_token(user)
local token = hash(user .. os.time() .. math.random())
local token = sha256.sha256(user .. os.time() .. math.random())
data.users[user].token = token
return token
end
function convert_password(password)
return hash(password .. "3m&LmNm7")
end
-- Does a complex hash of a string to make it harder to guess
function hash(str)
local hash = 0
local len = string.len(str)
local byte = 0
for i = 1, len do
byte = string.byte(str, i)
hash = bit32.band(hash * 31 + byte, 0xFFFFFFFF)
end
return hash
local salt = settings.get("auth_server.salt")
return sha256.sha256(password .. salt)
end
function log(str)