xCharliex

Password Generator

Jun 24th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.23 KB | None | 0 0
  1. — Simple Password Generator —
  2.  
  3. local pass = ""
  4.  
  5. local nums = {1,2,3,4,5,6,7,8,9,0}
  6.  
  7. local letters = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}
  8.  
  9. local special = {"/", ".", "_", ":", ";", "*", "-", "!", ",", "!", "'", "\""}
  10.  
  11. function genPass(length)
  12.    local n = 0
  13.    while n < tonumber(length)  do
  14.       local t
  15.       local op = math.random(1, 3)
  16.       --print(op)
  17.       if op == 1 then
  18.          local ul = math.random(1,2)
  19.          local i = letters[math.random(1,26)]
  20.          if ul == 1 then
  21.             t = string.lower(i)
  22.          else
  23.             t = string.upper(i)
  24.          end
  25.          pass = pass..t
  26.       elseif op == 2 then
  27.          pass = pass..nums[math.random(1,10)]
  28.       else
  29.          pass = pass..special[math.random(1,12)]
  30.       end
  31.       n = n + 1
  32.    end
  33.    return tostring(pass)
  34. end
  35.  
  36. print("Password Generator")
  37.  
  38. print("Choose a length for your password: ")
  39. local i = io.read()
  40. if tonumber(i) == 0 then
  41.    print("Not a number! Generating a password 20 characters long.")
  42.    print("Password generated: ")
  43.    print(genPass(20))
  44. else
  45.    print("Password generated: ")
  46.    print(genPass(i))
  47. end
  48. sys.alert("vib")
Add Comment
Please, Sign In to add comment