Skip to content

Instantly share code, notes, and snippets.

@Carleslc
Last active October 5, 2018 23:21
Show Gist options
  • Save Carleslc/3946123c96407ee465a8d8464ece2655 to your computer and use it in GitHub Desktop.
Save Carleslc/3946123c96407ee465a8d8464ece2655 to your computer and use it in GitHub Desktop.
SimplePasswordGenerator created by Carleslc - https://repl.it/@Carleslc/SimplePasswordGenerator
function randPW(length, strong)
local index, pw, rnd = 0, ""
local chars = {
"ABCDEFGHIJKLMNPQRSTUVWXYZ", -- O
"abcdefghijklmnopqrstuvwxyz",
"123456789" -- 0
}
if strong then
table.insert(chars, "!\\#$%&()*+,-./:;<=>?@[]^_{|}~") -- '"
end
repeat
index = index + 1
rnd = math.random(chars[index]:len())
if math.random(2) == 1 then
pw = pw .. chars[index]:sub(rnd, rnd)
else
pw = chars[index]:sub(rnd, rnd) .. pw
end
index = index % #chars
until pw:len() >= length
return pw
end
function generatePassword(length, strong)
math.randomseed(os.time())
return randPW(length, strong)
end
print("SIMPLE: " .. generatePassword(8))
print("STRONG: " .. generatePassword(16, true))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment