From 7a1c58009b2b2bc8e344b626bfd541e54e567b46 Mon Sep 17 00:00:00 2001 From: DanyLE Date: Fri, 2 Sep 2022 20:10:35 +0200 Subject: [PATCH] add random salt string generation in core API --- APIs/api.lua | 2 +- APIs/utils.lua | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/APIs/api.lua b/APIs/api.lua index 07f9b65..8576093 100644 --- a/APIs/api.lua +++ b/APIs/api.lua @@ -1,4 +1,4 @@ - +math.randomseed(os.clock()) package.cpath = __api__.apiroot..'/?.so' require("antd") std = modules.std() diff --git a/APIs/utils.lua b/APIs/utils.lua index 93c4728..8f933c8 100644 --- a/APIs/utils.lua +++ b/APIs/utils.lua @@ -145,4 +145,17 @@ end function firstToUpper(str) return (str:gsub("^%l", string.upper)) +end + + +local charset = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890" + +function utils.generate_salt(length) + local ret = {} + local r + for i = 1, length do + r = math.random(1, #charset) + table.insert(ret, charset:sub(r, r)) + end + return table.concat(ret) end \ No newline at end of file