Advertisement
faubiguy

Generate Access Code

Mar 13th, 2013
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.82 KB | None | 0 0
  1. generate = true
  2. if fs.exists("PasswordFiles/AccessCode") then
  3.  print("Access Code already exists.")
  4.  print("Would you like to overwrite it?")
  5.  print("Press 'Y' or 'N' to choose")
  6.  while true do
  7.   event, keyCode = os.pullEvent("key")
  8.   if keyCode == 21 then
  9.    generate = true
  10.    break
  11.   elseif keyCode == 49 then
  12.    generate = false
  13.    break
  14.   end
  15.  end
  16. end
  17.  
  18. function generateCode()
  19.  acFile = fs.open(".PasswordFiles/AccessCode", "wb")
  20.  math.randomseed(os.time())
  21.  for n = 1, 100 do
  22.   acByte = math.random(33, 126)
  23.   acFile.write(acByte)
  24.  end
  25.  acFile.close()
  26. end
  27.  
  28. if generate then
  29.  if fs.exists(".PasswordFiles") then
  30.   if fs.isDir(".PasswordFiles") then
  31.    generateCode()
  32.   else
  33.    print("Error: /.PasswordFiles is already a file")
  34.   end
  35.  else
  36.   fs.makeDir(".PasswordFiles")
  37.   generateCode()
  38.  end
  39. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement