Last active
October 5, 2018 23:21
-
-
Save Carleslc/3946123c96407ee465a8d8464ece2655 to your computer and use it in GitHub Desktop.
SimplePasswordGenerator created by Carleslc - https://repl.it/@Carleslc/SimplePasswordGenerator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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