This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
_Black_Viper_'s profile picture

ViperSecurity - Advanced Locking

Started by _Black_Viper_, 02 October 2012 - 05:28 PM
_Black_Viper_ #1
Posted 02 October 2012 - 07:28 PM
ViperSecurity


Secure locking with multiple customisable settings


Can be terminated with a seperate password to access the computer

Can be used wirelessly between two seperate computers

Locks with either passwords or floppy disks

Locks out hackers after 3 failed tries

Locks out hackers after rebooting

Displays message to a monitor

Locks doors



Screenshots

Spoiler







How to Layout the Computers

Spoiler

It is possible to hack this system by using a disk with a startup program installed

However, you can stop this by doing the following:



Password Lock


To prevent hackers hacking your password lock, simply remove any disk drives adjacent to the computer


Example:





Floppy Disk Lock


Now here comes a problem. With a floppy disk lock, you can't just remove all the disk drives since it requires one


What you can do instead to prevent hackers with the Floppy Disk Lock is this:



With this setup, if the computer is rebooted it will run the ViperSecurity disk every time




Update Log

Spoiler

1.1.0

Added monitor display (works best with 1x1 monitors)

Added wireless option

Fixed several bugs


1.0.3

Added functions

Added customisation of maximum attempts and lock time

Added terminated window


1.0.2

Fixed a hacking method

It will now only eject the disk with the password on it


1.0.1

Fixed lock window resizing


1.0.0

First release




Code

Spoiler


--Functions
function savePass(a,b,c,d)
passStore = fs.open(".ViperSecurity/passwords.vsec","a")
passStore.writeLine(a)
passStore.writeLine(:(/>/>
passStore.writeLine(c)
passStore.writeLine(d)
passStore.close()
end

function openPass()
passStore = fs.open(".ViperSecurity/passwords.vsec","r")
pass = passStore.readLine()
tpass = passStore.readLine()
FDES = passStore.readLine()
eject = passStore.readLine()
passStore.close()
end

function saveWirelessData(a,:D/>/>
wirelessDataStore = fs.open(".ViperSecurity/wireless.vsec","a")
wirelessDataStore.writeLine(a)
wirelessDataStore.writeLine(B)/>/>
wirelessDataStore.close()
end

function openWirelessData()
wirelessDataStore = fs.open(".ViperSecurity/wireless.vsec","r")
connectedComputerString = wirelessDataStore.readLine()
wirelessReceiver = wirelessDataStore.readLine()
wirelessDataStore.close()
connectedComputer = tonumber(connectedComputerString)
end

function power()
redstone.setOutput("right",true)
redstone.setOutput("front",true)
redstone.setOutput("left",true)
redstone.setOutput("back",true)
redstone.setOutput("top",true)
redstone.setOutput("bottom",true)
os.sleep(3)
redstone.setOutput("right",false)
redstone.setOutput("front",false)
redstone.setOutput("left",false)
redstone.setOutput("back",false)
redstone.setOutput("top",false)
redstone.setOutput("bottom",false)
end

function ejectDisk(a)
if disk.getMountPath("top") ~= nil then
  if fs.exists(disk.getMountPath("top").."/"..a) then
   disk.eject("top")
  end
end
if disk.getMountPath("bottom") ~= nil then
  if fs.exists(disk.getMountPath("bottom").."/"..a) then
   disk.eject("bottom")
  end
end
if disk.getMountPath("front") ~= nil then
  if fs.exists(disk.getMountPath("front").."/"..a) then
   disk.eject("front")
  end
end
if disk.getMountPath("right") ~= nil then
  if fs.exists(disk.getMountPath("right").."/"..a) then
   disk.eject("right")
  end
end
if disk.getMountPath("back") ~= nil then
  if fs.exists(disk.getMountPath("back").."/"..a) then
   disk.eject("back")
  end
end
if disk.getMountPath("left") ~= nil then
  if fs.exists(disk.getMountPath("left").."/"..a) then
   disk.eject("left")
  end
end
end

function lockComputer()
timeLocked = timeLocked - 1
term.clear()
term.setCursorPos(1,7)
clearMonitors()
printMonitors("")
printMonitors(" Protected by")
printMonitors("Viper Security")
printMonitors("")
printMonitors("  Incorrect")
printMonitors("   password")
printMonitors("")
printMonitors(" Locked for "..timeLocked)
printMonitors("   seconds")
print("			,-========================-,")
print("			|	Incorrect password	|")
print("			|						  |")
print("			|						  |")
if timeLocked < 10 then
  print("			|  Locked for "..timeLocked.." seconds	|")
elseif timeLocked < 100 then
  print("			|  Locked for "..timeLocked.." seconds   |")
elseif timeLocked < 1000 then
  print("			|  Locked for "..timeLocked.." seconds  |")
end
print("			|__________________________|")
os.sleep(1)
end

function lockComputerReboot()
timeLocked = lockTime
while timeLocked > 0 do
  term.clear()
  term.setCursorPos(1,7)
  clearMonitors()
  printMonitors("")
  printMonitors(" Protected by")
  printMonitors("Viper Security")
  printMonitors("")
  printMonitors(" OS Rebooted")
  printMonitors("")
  printMonitors(" Locked for "..timeLocked)
  printMonitors("   seconds")
  print("			,-========================-,")
  print("			|		OS Rebooted	   |")
  print("			|						  |")
  print("			|						  |")
  if timeLocked < 10 then
  print("			|  Locked for "..timeLocked.." seconds	|")
elseif timeLocked < 100 then
  print("			|  Locked for "..timeLocked.." seconds   |")
elseif timeLocked < 1000 then
  print("			|  Locked for "..timeLocked.." seconds  |")
end
  print("			|__________________________|")
  timeLocked = timeLocked - 1
  os.sleep(1)
end
end

function saveLockData(a,B)/>/>
lockTimeStore = fs.open(".ViperSecurity/locktime.vsec","a")
lockTimeStore.writeLine(a)
lockTimeStore.writeLine(B)/>/>
lockTimeStore.close()
end

function openLockData()
lockTimeStore = fs.open(".ViperSecurity/locktime.vsec","r")
lockTimeString = lockTimeStore.readLine()
maxTriesString = lockTimeStore.readLine()
lockTimeStore.close()
lockTime = tonumber(lockTimeString)
maxTries = tonumber(maxTriesString)
end

function getMonitors()
if peripheral.getType("top") == "monitor" then
  x,y = monTop.getSize()
  textScale = x/2
  monTop.setTextScale(textScale)
  monTop = peripheral.wrap("top")
  monTopExists = true
end
if peripheral.getType("bottom") == "monitor" then
  monBottom = peripheral.wrap("bottom")
  monBottomExists = true
  x,y = monBottom.getSize()
  textScale = x/2
  monBottom.setTextScale(0.5)
end
if peripheral.getType("front") == "monitor" then
  x,y = monFront.getSize()
  textScale = x/2
  monFront.setTextScale(textScale)
  monFront = peripheral.wrap("front")
  monFrontExists = true
end
if peripheral.getType("right") == "monitor" then
  x,y = monRight.getSize()
  textScale = x/2
  monRight.setTextScale(textScale)
  monRight = peripheral.wrap("right")
  monRightExists = true
end
if peripheral.getType("back") == "monitor" then
  x,y = monBack.getSize()
  textScale = x/2
  monBack.setTextScale(textScale)
  monBack = peripheral.wrap("back")
  monBackExists = true
end
if peripheral.getType("left") == "monitor" then
  x,y = monLeft.getSize()
  textScale = x/2
  monLeft.setTextScale(textScale)
  monLeft = peripheral.wrap("left")
  monLeftExists = true
end
end

function printMonitors(a)
if monTopExists == true then
  x,y = monTop.getCursorPos()
  monTop.setCursorPos(1,y+1)
  monTop.write(a)
end
if monBottomExists == true then
  x,y = monBottom.getCursorPos()
  monBottom.setCursorPos(1,y+1)
  monBottom.write(a)
end
if monFrontExists == true then
  x,y = monFront.getCursorPos()
  monFront.setCursorPos(1,y+1)
  monFront.write(a)
end
if monRightExists == true then
  x,y = monRight.getCursorPos()
  monRight.setCursorPos(1,y+1)
  monRight.write(a)
end
if monBackExists == true then
  x,y = monBack.getCursorPos()
  monBack.setCursorPos(1,y+1)
  monBack.write(a)
end
if monLeftExists == true then
  x,y = monLeft.getCursorPos()
  monLeft.setCursorPos(1,y+1)
  monLeft.write(a)
end
end

function clearMonitors()
if monTopExists == true then
  monTop.setCursorPos(1,0)
  monTop.clear()
end
if monBottomExists == true then
  monBottom.setCursorPos(1,0)
  monBottom.clear()
end
if monFrontExists == true then
  monFront.setCursorPos(1,0)
  monFront.clear()
end
if monRightExists == true then
  monRight.setCursorPos(1,0)
  monRight.clear()
end
if monBackExists == true then
  monBack.setCursorPos(1,0)
  monBack.clear()
end
if monLeftExists == true then
  monLeft.setCursorPos(1,0)
  monLeft.clear()
end
end

function openModem()
rednet.open("top")
rednet.open("bottom")
rednet.open("front")
rednet.open("right")
rednet.open("back")
rednet.open("left")
end

function wirelessInput()
openModem()
print("Connecting...")
while connected ~= true do
  rednet.broadcast("vipersecurityconnecting")
  a,b,c = rednet.receive()
  if b == "vipersecurityconnected" and a == connectedComputer then
   print("Connected to computer "..a..", "..c.."m away.")
   connected = true
  end
end
end

function wirelessOutput()
openModem()
print("Waiting for connection...")
while connected ~= true do
  a,b,c = rednet.receive()
  if b == "vipersecurityconnecting" and a == connectedComputer then
   rednet.send(a,"vipersecurityconnected")
   connected = true
   wirelessReceiver = "true"
  end
end
end

function wirelessInputSetup()
openModem()
print("This computer's ID is "..os.computerID())
print("Connecting, check other computer")
while connected ~= true do
  rednet.broadcast("vipersecurityconnecting")
  a,b,c = rednet.receive(1)
  if b == "vipersecurityconnected" then
   print("Connected to computer "..a..", "..c.."m away.")
   print("Do you want to use this connection? y/n")
   yn = read()
   if yn == "y" then
	connectedComputer = a
connected = true
rednet.send(connectedComputer,"vipersecuritysuccess")
continue = true
saveWirelessData(connectedComputer,"true")
   end
  else
   os.sleep(0.3)
  end
end
end

function wirelessOutputSetup()
openModem()
print("This computer's ID is "..os.computerID())
print("Connecting...")
while connected ~= true do
  a,b,c = rednet.receive(1)
  if b == "vipersecurityconnecting" then
   print("Connected to computer "..a..", "..c.."m away.")
   print("Do you want to use this connection? y/n")
   yn = read()
   if yn == "y" then
	connectedComputer = a
	print("Please finish setup on the other computer")
while success ~= true do
rednet.send(connectedComputer,"vipersecurityconnected")
a,b,c = rednet.receive(1)
if a == connectedComputer and b == "vipersecuritysuccess" then
success = true
print("Success!")
saveWirelessData(connectedComputer,"true")
	  connected = true
	  continue = false
	  correctInput = true
end
end
   end
  else
   os.sleep(0.2)
  end
end
end

--Setup
if fs.exists(".ViperSecurity/passwords.vsec") == false and fs.exists(".ViperSecurity/wireless.vsec") == false then
fs.makeDir(".ViperSecurity")
correctInput = false
while correctInput == false do
  passSet = "false"
  print("Do you want to use wireless? y/n")
  yn = read()
  if yn == "y" then
   print("To use wireless, you will need two computers,")
   print("one into which you will enter the password/disk")
   print("and another which will receive the password and")
   print("power redstone or allow access if it's correct.")
   print("Both need a modem attached.")
   print("Press enter to continue")
   read()
   print("Do you want:")
   print("1. To enter the password/disk into this computer")
   print("2. To have this computer receive the password")
   numinput = read()
   while correctInput2 ~= true do
if numinput == "1" then
wirelessInputSetup()
correctInput2 = true
elseif numinput == "2" then
wirelessOutputSetup()
correctInput2 = true
else
print("Please enter either 1 or 2")
	end
   end
  else
   connectedComputer = "-1"
   wirelessReceiver = "false"
   continue = true
  end
  if continue == true then
   print("Would you like to:")
   print("1. Use a password lock")
   print("2. Use a floppy disk lock")
   numinput = read()
   if numinput == "1" or numinput == "2" then
	while passSet == "false" do
	 print("Do you wish to set a password which can be")
	 print("used to power redstone on all sides of the")
	 print("computer? (e.g. Door locks) y/n")
	 yn = read()
	 if yn == "y" then
	  print("Enter your desired password (no spaces):")
	  pass = read()
	  passSet = "true"
	 else
	  pass = "false"
	 end
	 correctInput = true
	 print("Do you wish to set a password which can be")
	 print("used to terminate ViperSecurity and access")
	 print("the operating system? (Computer Lock) y/n")
	 yn = read()
	 if yn == "y" then
	  print("Enter termination password (no spaces):")
	  tpass = read()
	  passSet = "true"
	 else
	  tpass = "false"
	 end
	 if passSet == "false" then
	  print("You didn't set a password!")
	  os.sleep(1)
	 end
	end
   end
   if numinput == "1" then
	eject = false
	FDES = "false"
	lockTime = 60
	maxTries = 3
	enterPressed = false
	while enterPressed == false do
	 term.clear()
	 term.setCursorPos(1,1)
	 print("After how many incorrect attempts do")
	 print("you want the computer to be locked?")
	 print("(Change with arrow keys and then press enter)")
	 if maxTries == 0 then
print("< Never lock the computer >")
elseif maxTries ~= 1 then
	  print("After < "..maxTries.." > incorrect attempts")
else
print("After < "..maxTries.." > incorrect attempt")
end
	 a,b = os.pullEvent()
	 if a == "key" then
	  if b == 203 and maxTries > 0 then
	   maxTries = maxTries - 1
	  elseif b == 205 and maxTries < 999 then
	   maxTries = maxTries + 1
	  elseif b == 28 then
	   enterPressed = true
	  end
	 end
	end
enterPressed = false
	while enterPressed == false do
	 term.clear()
	 term.setCursorPos(1,1)
if maxTries ~= 0 then
	print("How long do you want the computer to be")
	  print("locked for after either "..maxTries.." incorrect attempts")
	  print("have been made or the computer is rebooted?")
	print("(Change with arrow keys and then press enter)")
	  if lockTime ~= 1 then
	   print("For < "..lockTime.." > seconds")
else
  print("For < "..lockTime.." > second")
end
else
print("How long do you want the computer to be")
	print("locked for after the computer is rebooted?")
	print("(Change with arrow keys and then press enter)")
	if lockTime ~= 1 then
	   print("For < "..lockTime.." > seconds")
else
  print("For < "..lockTime.." > second")
end
	 end
a,b = os.pullEvent()
if a == "key" then
if b == 203 and lockTime > 0 then
  lockTime = lockTime - 1
elseif b == 205 and lockTime < 999 then
  lockTime = lockTime + 1
elseif b == 28 then
  enterPressed = true
end
	end
	end
	saveLockData(lockTime,maxTries)
	savePass(pass,tpass,FDES,eject)
	print("Information stored! Starting ViperSecurity...")
	os.sleep(1.5)
   elseif numinput == "2" then
	FDES = "true"
	correctInput = true
	print("Do you want the disk to be")
	print("ejected automatically? y/n")
	yn = read()
	if yn == "y" then
	 eject = "true"
	else
	 eject = "false"
	end
	savePass(pass,tpass,FDES,eject)
saveWirelessData(connectedComputer,wirelessReceiver)
	print("To use the floppy disk entry system,")
	print("create the file disk/"..pass)
	print("and place a disk drive adjacent to")
	print("the computer. When you place the disk")
	print("in the drive the door will open.")
	print("This will also work with a termination")
	print("password if set.")
	print("Press enter to continue")
	read()
	print("Information stored! Starting ViperSecurity...")
	os.sleep(2)
   else
	print("Please enter either 1 or 2")
	os.sleep(2)
   end
   reboot = false
  end
end
end

--Variables
os.pullEvent = os.pullEventRaw
if fs.exists(".ViperSecurity/wireless.vsec") == true then
openWirelessData()
openModem()
end
if wirelessReceiver ~= "true" then
openPass()
if fs.exists(".ViperSecurity/locktime.vsec") == true then
  openLockData()
end
getMonitors()
clearMonitors()
timeLocked = 0
tries = maxTries
end

--Floppy Disk
if FDES == "true" then
printMonitors("Enter floppy disk")
term.clear()
term.setCursorPos(1,8)
clearMonitors()
printMonitors("")
printMonitors(" Protected by")
printMonitors("Viper Security")
printMonitors("")
printMonitors(" Enter floppy")
printMonitors("	disk")
print("				,-===============-,")
print("				|Enter floppy disk|")
print("				|_________________|")
while true do
  if fs.exists("disk/"..pass) or fs.exists("disk2/"..pass) or fs.exists("disk3/"..pass) then
   if eject == "true" then
	ejectDisk(pass)
   end
   if fs.exists(".ViperSecurity/wireless.vsec") == true then
	rednet.send(connectedComputer,"vipersecuritycorrectpass")
	sleep(3)
   else
	power()
   end
  elseif fs.exists("disk/"..tpass) or fs.exists("disk2/"..tpass) or fs.exists("disk3/"..tpass) and tpass ~= "false" then
   if eject == "true" then
	ejectDisk(tpass)
   end
   if fs.exists(".ViperSecurity/wireless.vsec") == true then
	rednet.send(connectedComputer,"vipersecuritycorrecttpass")
	error()
   else
	power()
error()
   end
  end
  os.sleep(0.2)
end
end

--Password
if reboot ~= false and wirelessReceiver == "false" then
lockComputerReboot()
end
if wirelessReceiver == "true" then
print("Waiting for password...")
while true do
  a,b,c = rednet.receive()
  if a == connectedComputer and b == "vipersecuritycorrectpass" then
   power()
  elseif a == connectedComputer and b == "vipersecuritycorrecttpass" then
   power()
   error()
  end
end
else
while true do
  term.clear()
  term.setCursorPos(1,7)
  if tries == maxTries then
   clearMonitors()
   printMonitors("")
   printMonitors(" Protected by")
   printMonitors("Viper Security")
   printMonitors("")
   printMonitors("Enter Password")
   print("			,-========================-,")
   print("			|This computer is protected|")
   print("			|	 by ViperSecurity	 |")
   print("			|						  |")
   print("			|	  Enter password	  |")
   print("			|__________________________|")
  else
   clearMonitors()
   printMonitors("")
   printMonitors(" Protected by")
   printMonitors("Viper Security")
   printMonitors("")
   printMonitors("  Incorrect")
   printMonitors("   password")
   printMonitors("")
   printMonitors("   Attempts")
   printMonitors(" remaining: "..tries)
   print("			,-========================-,")
   print("			|	Incorrect password	|")
   if tries < 10 then
	print("			|  Attempts remaining: "..tries.."   |")
   elseif tries < 100 then
	print("			|  Attempts remaining: "..tries.."  |")
   elseif tries < 1000 then
	print("			|  Attempts remaining: "..tries.." |")
   end
   print("			|						  |")
   print("			|	  Enter password	  |")
   print("			|__________________________|")
  end
  userInput = read("*")
  if userInput == pass then
   tries = maxTries
   term.clear()
   term.setCursorPos(1,7)
   clearMonitors()
   printMonitors("")
   printMonitors(" Protected by")
   printMonitors("Viper Security")
   printMonitors("")
   printMonitors("   Correct!")
   print("			,-========================-,")
   print("			|						  |")
   print("			|		 Correct!		 |")
   print("			|						  |")
   print("			|						  |")
   print("			|__________________________|")
   if fs.exists(".ViperSecurity/wireless.vsec") == true then
	rednet.send(connectedComputer,"vipersecuritycorrectpass")
	sleep(3)
   else
	power()
   end
  elseif userInput == tpass and tpass ~= "false" then
   term.clear()
   term.setCursorPos(1,7)
   clearMonitors()
   printMonitors("")
   printMonitors(" Protected by")
   printMonitors("Viper Security")
   printMonitors("")
   printMonitors("  Terminated")
   print("			,-========================-,")
   print("			|						  |")
   print("			|		Terminated		|")
   print("			|						  |")
   print("			|						  |")
   print("			|__________________________|")
   if fs.exists(".ViperSecurity/wireless.vsec") == true then
	rednet.send(connectedComputer,"vipersecuritycorrecttpass")
   end
   error()
  elseif tries == 1 then
   timeLocked = lockTime
   tries = maxTries
   while timeLocked > 0 do
	lockComputer()
   end
  elseif tries ~= 0 then
   tries = tries - 1
  end
end
end



To install automatically put 'pastebin get 20Pj16bj startup' into a computer


If this doesn't work, try 'rom/programs/http/pastbin get 20Pj16bj startup'


This is my first program, so any constructive criticism and advice is greatly appreciated
Novicode #2
Posted 02 October 2012 - 08:27 PM
Hey, could you maybe include some images? I can't just use it now cuz I'm at school though.
_Black_Viper_ #3
Posted 02 October 2012 - 08:48 PM
Hey, could you maybe include some images? I can't just use it now cuz I'm at school though.
Sure, I've added some screenshots into a spoiler.
jag #4
Posted 02 October 2012 - 09:06 PM
Oh god, please add some alignment on your code! It's almost impossible to read!!
You know, something like this:
Spoiler
if fs.exists("ViperSecurity/passwords.vsecurity") == false then
  correctInput = false
  while correctInput == false do
    print("Would you like to:")
    print("1. Use a password lock")
    print("2. Use a floppy disk lock")
    numinput = read()
    if numinput == "1" or numinput == "2" then
      print("Enter your desired password:")
      pass = read()
      correctInput = true
      print("Do you wish to set another password which")
      print("can be used to terminate the program")
      print("and access the operating system? y/n")
      yn = read()
      if yn == "y" then
        print("Enter termination password:")
        tpass = read()
      else
        tpass = "false"
      end
    end
    if numinput == "1" then
      eject = "false"
      fs.makeDir("ViperSecurity")
      passStore = fs.open("ViperSecurity/passwords.vsecurity","a")
      passStore.writeLine(pass)
      passStore.writeLine(tpass)
      passStore.writeLine("false")
      passStore.writeLine(eject)
      passStore.close()
      print("Passwords set!")
      os.sleep(1.5)
    elseif numinput == "2" then
      correctInput = true
      print("Do you want the disk to be")
      print("ejected automatically? y/n")
      yn = read()
      if yn == "y" then
        eject = "true"
      else
        eject = "false"
      end
      passStore = fs.open("ViperSecurity/passwords.vsecurity","a")
      passStore.writeLine(pass)
      passStore.writeLine(tpass)
      passStore.writeLine("true")
      passStore.writeLine(eject)
      passStore.close()
      print("To use the floppy disk entry system,")
      print("create the file disk/"..pass)
      print("and place a disk drive adjacent to")
      print("the computer. When you place the disk")
      print("in the drive the door will open.")
      print("This will also work with a termination")
      print("password if set.")
      print("Press enter to continue")
      read()
      print("All done! Starting ViperSecurity...")
      os.sleep(2)
    else
      print("Please enter either 1 or 2")
      os.sleep(2)
    end
    reboot = false
  end
end
os.pullEvent = os.pullEventRaw
passStore = fs.open("vipersecurity/passwords.vsecurity","r")
pass = passStore.readLine()
tpass = passStore.readLine()
FDES = passStore.readLine()
eject = passStore.readLine()
passStore.close()
if FDES == "true" then
  term.clear()
  term.setCursorPos(1,8)
  print("                ,-===============-,")
  print("                |Enter floppy disk|")
  print("                |_________________|")
  while true do
    if fs.exists("disk/"..pass) then
      if eject == "true" then
        disk.eject("top")
        disk.eject("bottom")
        disk.eject("right")
        disk.eject("front")
        disk.eject("left")
        disk.eject("back")
      end
      redstone.setOutput("right",true)
      redstone.setOutput("front",true)
      redstone.setOutput("left",true)
      redstone.setOutput("back",true)
      redstone.setOutput("top",true)
      redstone.setOutput("bottom",true)
      os.sleep(3)
      redstone.setOutput("right",false)
      redstone.setOutput("front",false)
      redstone.setOutput("left",false)
      redstone.setOutput("back",false)
      redstone.setOutput("top",false)
      redstone.setOutput("bottom",false)
    elseif fs.exists("disk/"..tpass) and tpass ~= "false" then
      if eject == "true" then
        disk.eject("top")
        disk.eject("bottom")
        disk.eject("right")
        disk.eject("front")
        disk.eject("left")
        disk.eject("back")
      end
      error()
    end
    os.sleep(0.1)
  end
end
if reboot ~= false then
  locked = 60
else
  locked = 0
end
while locked > 0 do
  term.clear()
  term.setCursorPos(1,7)
  print("           ,-========================-,")
  print("           |       OS Rebooted        |")
  print("           |                          |")
  print("           |                          |")
  print("           |  Locked for "..locked.." seconds   |")
  print("           |__________________________|")
  locked = locked - 1
  os.sleep(1)
end
tries = 3
while true do
  term.clear()
  term.setCursorPos(1,7)
  while locked > 0 do
    locked = locked - 1
    print("           ,-========================-,")
    print("           |    Incorrect password    |")
    print("           |                          |")
    print("           |                          |")
    print("           |  Locked for "..locked.." seconds   |")
    print("           |__________________________|")
    os.sleep(1)
    term.clear()
    term.setCursorPos(1,7)
    tries = 3
  end
  if tries == 3 then
    print("           ,-========================-,")
    print("           |This building is protected|")
    print("           |     by ViperSecurity     |")
    print("           |                          |")
    print("           |      Enter password      |")
    print("           |__________________________|")
  else
    print("           ,-========================-,")
    print("           |    Incorrect password    |")
    print("           |    Tries remaining: "..tries.."    |")
    print("           |                          |")
    print("           |      Enter password      |")
    print("           |__________________________|")
  end
  input = read("*")
  if input==pass then
    tries = 3
    term.clear()
    term.setCursorPos(1,7)
    print("           ,-========================-,")
    print("           |                          |")
    print("           |         Correct!         |")
    print("           |                          |")
    print("           |                          |")
    print("           |__________________________|")
    redstone.setOutput("right",true)
    redstone.setOutput("front",true)
    redstone.setOutput("left",true)
    redstone.setOutput("back",true)
    redstone.setOutput("top",true)
    redstone.setOutput("bottom",true)
    os.sleep(3)
    redstone.setOutput("right",false)
    redstone.setOutput("front",false)
    redstone.setOutput("left",false)
    redstone.setOutput("back",false)
    redstone.setOutput("top",false)
    redstone.setOutput("bottom",false)
  elseif input == tpass and tpass ~= "false" then
    error()
  elseif tries == 1 then
    term.clear()
    term.setCursorPos(1,7)
    print("           ,-========================-,")
    print("           |    Incorrect password    |")
    print("           |                          |")
    print("           |                          |")
    print("           |  Locked for 1 minute     |")
    print("           |__________________________|")
    locked = 60
    os.sleep(1)
  else
    tries = tries - 1
  end
end
jag #5
Posted 02 October 2012 - 09:23 PM
When it counts down while in "lockdown" it goes from 60 to 0, but when it enters the digit 9 and below, wont the "frame/scare/window" be kind of messed up?
Just a tiny amount, but still?

Found out that this looks really weird, so look at it here instead: 1kBC20Gg
SpoilerGoes from 60:
			,-========================-,
			|	Incorrect password	  |
			|											  |
			|											  |
			|  Locked for 60 seconds   |
			|__________________________|
And when it hits 9:

			,-========================-,
			|	Incorrect password	  |
			|											  |
			|											  |
			|  Locked for 9 seconds   |
			|__________________________|
All you could do is just:
print("			,-========================-,")
print("			|	Incorrect password	  |")
print("			|											  |")
print("			|											  |")
if locked < 10 then
  print("			|  Locked for "..locked.." seconds	|") -- With an extra space at the end
else
  print("			|  Locked for "..locked.." seconds   |") -- Without the extra space
end
print("			|__________________________|")
_Black_Viper_ #6
Posted 02 October 2012 - 09:27 PM
Oh god, please add some alignment on your code! It's almost impossible to read!!
You know, something like this:
Spoiler
if fs.exists("ViperSecurity/passwords.vsecurity") == false then
  correctInput = false
  while correctInput == false do
	print("Would you like to:")
	print("1. Use a password lock")
	print("2. Use a floppy disk lock")
	numinput = read()
	if numinput == "1" or numinput == "2" then
	  print("Enter your desired password:")
	  pass = read()
	  correctInput = true
	  print("Do you wish to set another password which")
	  print("can be used to terminate the program")
	  print("and access the operating system? y/n")
	  yn = read()
	  if yn == "y" then
		print("Enter termination password:")
		tpass = read()
	  else
		tpass = "false"
	  end
	end
	if numinput == "1" then
	  eject = "false"
	  fs.makeDir("ViperSecurity")
	  passStore = fs.open("ViperSecurity/passwords.vsecurity","a")
	  passStore.writeLine(pass)
	  passStore.writeLine(tpass)
	  passStore.writeLine("false")
	  passStore.writeLine(eject)
	  passStore.close()
	  print("Passwords set!")
	  os.sleep(1.5)
	elseif numinput == "2" then
	  correctInput = true
	  print("Do you want the disk to be")
	  print("ejected automatically? y/n")
	  yn = read()
	  if yn == "y" then
		eject = "true"
	  else
		eject = "false"
	  end
	  passStore = fs.open("ViperSecurity/passwords.vsecurity","a")
	  passStore.writeLine(pass)
	  passStore.writeLine(tpass)
	  passStore.writeLine("true")
	  passStore.writeLine(eject)
	  passStore.close()
	  print("To use the floppy disk entry system,")
	  print("create the file disk/"..pass)
	  print("and place a disk drive adjacent to")
	  print("the computer. When you place the disk")
	  print("in the drive the door will open.")
	  print("This will also work with a termination")
	  print("password if set.")
	  print("Press enter to continue")
	  read()
	  print("All done! Starting ViperSecurity...")
	  os.sleep(2)
	else
	  print("Please enter either 1 or 2")
	  os.sleep(2)
	end
	reboot = false
  end
end
os.pullEvent = os.pullEventRaw
passStore = fs.open("vipersecurity/passwords.vsecurity","r")
pass = passStore.readLine()
tpass = passStore.readLine()
FDES = passStore.readLine()
eject = passStore.readLine()
passStore.close()
if FDES == "true" then
  term.clear()
  term.setCursorPos(1,8)
  print("				,-===============-,")
  print("				|Enter floppy disk|")
  print("				|_________________|")
  while true do
	if fs.exists("disk/"..pass) then
	  if eject == "true" then
		disk.eject("top")
		disk.eject("bottom")
		disk.eject("right")
		disk.eject("front")
		disk.eject("left")
		disk.eject("back")
	  end
	  redstone.setOutput("right",true)
	  redstone.setOutput("front",true)
	  redstone.setOutput("left",true)
	  redstone.setOutput("back",true)
	  redstone.setOutput("top",true)
	  redstone.setOutput("bottom",true)
	  os.sleep(3)
	  redstone.setOutput("right",false)
	  redstone.setOutput("front",false)
	  redstone.setOutput("left",false)
	  redstone.setOutput("back",false)
	  redstone.setOutput("top",false)
	  redstone.setOutput("bottom",false)
	elseif fs.exists("disk/"..tpass) and tpass ~= "false" then
	  if eject == "true" then
		disk.eject("top")
		disk.eject("bottom")
		disk.eject("right")
		disk.eject("front")
		disk.eject("left")
		disk.eject("back")
	  end
	  error()
	end
	os.sleep(0.1)
  end
end
if reboot ~= false then
  locked = 60
else
  locked = 0
end
while locked > 0 do
  term.clear()
  term.setCursorPos(1,7)
  print("		   ,-========================-,")
  print("		   |	   OS Rebooted		|")
  print("		   |						  |")
  print("		   |						  |")
  print("		   |  Locked for "..locked.." seconds   |")
  print("		   |__________________________|")
  locked = locked - 1
  os.sleep(1)
end
tries = 3
while true do
  term.clear()
  term.setCursorPos(1,7)
  while locked > 0 do
	locked = locked - 1
	print("		   ,-========================-,")
	print("		   |	Incorrect password	|")
	print("		   |						  |")
	print("		   |						  |")
	print("		   |  Locked for "..locked.." seconds   |")
	print("		   |__________________________|")
	os.sleep(1)
	term.clear()
	term.setCursorPos(1,7)
	tries = 3
  end
  if tries == 3 then
	print("		   ,-========================-,")
	print("		   |This building is protected|")
	print("		   |	 by ViperSecurity	 |")
	print("		   |						  |")
	print("		   |	  Enter password	  |")
	print("		   |__________________________|")
  else
	print("		   ,-========================-,")
	print("		   |	Incorrect password	|")
	print("		   |	Tries remaining: "..tries.."	|")
	print("		   |						  |")
	print("		   |	  Enter password	  |")
	print("		   |__________________________|")
  end
  input = read("*")
  if input==pass then
	tries = 3
	term.clear()
	term.setCursorPos(1,7)
	print("		   ,-========================-,")
	print("		   |						  |")
	print("		   |		 Correct!		 |")
	print("		   |						  |")
	print("		   |						  |")
	print("		   |__________________________|")
	redstone.setOutput("right",true)
	redstone.setOutput("front",true)
	redstone.setOutput("left",true)
	redstone.setOutput("back",true)
	redstone.setOutput("top",true)
	redstone.setOutput("bottom",true)
	os.sleep(3)
	redstone.setOutput("right",false)
	redstone.setOutput("front",false)
	redstone.setOutput("left",false)
	redstone.setOutput("back",false)
	redstone.setOutput("top",false)
	redstone.setOutput("bottom",false)
  elseif input == tpass and tpass ~= "false" then
	error()
  elseif tries == 1 then
	term.clear()
	term.setCursorPos(1,7)
	print("		   ,-========================-,")
	print("		   |	Incorrect password	|")
	print("		   |						  |")
	print("		   |						  |")
	print("		   |  Locked for 1 minute	 |")
	print("		   |__________________________|")
	locked = 60
	os.sleep(1)
  else
	tries = tries - 1
  end
end
The code should now be aligned. Thanks for pointing that out.

When it counts down while in "lockdown" it goes from 60 to 0, but when it enters the digit 9 and below, wont the "frame/scare/window" be kind of messed up?
Just a tiny amount, but still?

Goes from 60:
			,-========================-,
			|	Incorrect password	  |
			|											  |
			|											  |
			|  Locked for 60 seconds   |
			|__________________________|
And when it hits 9:

			,-========================-,
			|	Incorrect password	  |
			|											  |
			|											  |
			|  Locked for 9 seconds   |
			|__________________________|
All you could do is just:
print("			,-========================-,")
print("			|	Incorrect password	  |")
print("			|											  |")
print("			|											  |")
if locked < 10 then
  print("			|  Locked for "..locked.." seconds	|") -- With an extra space at the end
else
  print("			|  Locked for "..locked.." seconds   |") -- Without the extra space
end
print("			|__________________________|")
I've already fixed it :(/>/>
jag #7
Posted 02 October 2012 - 09:33 PM
But now your code got if locked < 9 then…
You should have < 10 or <= 9.
Or else it will start that at 8… :(/>/>
nolongerexistant #8
Posted 02 October 2012 - 09:43 PM
Can't you just input a floppy disk with a startup file and reboot the computer to bypass it?
_Black_Viper_ #9
Posted 02 October 2012 - 09:57 PM
But now your code got if locked < 9 then…
You should have < 10 or <= 9.
Or else it will start that at 8… :(/>/>
It's 'if locked > 9'.

Can't you just input a floppy disk with a startup file and reboot the computer to bypass it?
You can, so I'll look into this tomorrow since it's getting late for me.
_Black_Viper_ #10
Posted 03 October 2012 - 02:49 PM
I have updated ViperSecurity to 1.0.2, fixing a major flaw that allowed anyone to easily hack it (thanks Snakybo for pointing that out).

More features coming very soon!
_Black_Viper_ #11
Posted 03 October 2012 - 09:52 PM
Updated ViperSecurity to 1.0.3, simplifying the code by adding functions and allowing control of lock times and maximum attempts.
_Black_Viper_ #12
Posted 04 October 2012 - 03:09 PM
1.1.0 has been released, adding monitor displays and a wireless option.