Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("SHA")
- os.pullEvent = os.pullEventRaw
- redstone.setBundledOutput("left", colors.white)
- math.randomseed(os.time())
- term.clear()
- term.setCursorPos(1,1)
- print("Legoman Technologies door lock V1.0")
- print("Thank you to tomas1666 for his SHA1 code")
- modem = peripheral.wrap("top")
- if modem == nil then
- error("Modem not on top")
- end
- if modem.isPresentRemote("mag card reader_0") then
- reader = peripheral.wrap("mag card reader_0")
- print("Card reader connected")
- else
- error("Mag-card reader not found")
- end
- if modem.isPresentRemote("monitor_0") then
- monitor = peripheral.wrap("monitor_0")
- print("Monitor connected")
- else
- error("Monitor not found")
- end
- hashedPw = "Put the hashed admin password here"
- cardsFilePath = "Cards"
- cards = {""}
- chars = {"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","0","1","2","3","4","5","6","7","8","9", "@", "#", "$", "%", "&", "?"}
- newpass = ""
- cardNum = 0
- if fs.exists(cardsFilePath) then
- cardsFile = fs.open(cardsFilePath, "r")
- cards = textutils.unserialize(cardsFile.readAll())
- cardsFile.close()
- end
- while true do
- admin = false
- monitor.clear()
- monitor.setCursorPos(1,1)
- monitor.write("Welcome to Legoman Industries! Please insert a card!")
- reader.setInsertCardLight(true)
- event, p1,p2,p3 = os.pullEvent()
- if event == "mag_swipe" then
- if SHA.SHA1_2(p1) == hashedPw then
- admin = true
- end
- for x = 1, #cards do
- if SHA.SHA1_2(p1) == cards[x] then
- reader.setInsertCardLight(false)
- redstone.setBundledOutput("left", 0)
- os.sleep(3)
- redstone.setBundledOutput("left", colors.white)
- reader.setInsertCardLight(true)
- break
- end
- end
- end
- if admin == true then
- reader.setInsertCardLight(false)
- monitor.clear()
- monitor.setCursorPos(1,1)
- monitor.write("Admin granted! Insert blank card!")
- for z = 1,15 do
- case = math.random(1,2) -- randomly choose case (caps or lower)
- a = math.random(1,#chars) -- randomly choose a character from the "char" array
- if case == 1 then
- x=string.upper(chars[a]) -- uppercase if case = 1
- elseif case == 2 then
- x=string.lower(chars[a]) -- lowercase if case = 2
- end
- newpass = newpass..x
- end
- reader.setInsertCardLight(true)
- cardNum = #cards
- print(reader.beginWrite(newpass, cardNum..""))
- table.insert(cards, SHA.SHA1_2(newpass))
- while reader.isWaiting() do
- end
- reader.setInsertCardLight(false)
- monitor.clear()
- monitor.setCursorPos(1,1)
- monitor.write("New card created!")
- newpass = ""
- end
- os.sleep(1)
- cardsFile = fs.open(cardsFilePath, "w")
- cardsFile.write(textutils.serialize(cards))
- cardsFile.close()
- end
Add Comment
Please, Sign In to add comment