So i found the mag card readers we have, and decided to play with them and a bit of crypto to make a door that requires a magnetic card to be swiped. Here's how it works: An admin card is swiped, which has a hardcoded password (stored as a hash in the computer). The computer accepts the card if it is an admin card and prompts the user to insert a card. The computer writes a random 15 character password to the card, and stores an SHA1 hashed version in its memory, creating a door card. When a door card is swiped, the door opens for 3 seconds (under optimal TPS, if this matters). Here's the hardware needed: A door closed by redstone. A computer, advanced or regular. A monitor and mag card reader connected by wired modems to the computer Optionally, you can have readers away from the monitor to have more than one reader open the door. Only the first reader connected will work to make cards. This is because the computer gets a "mag_swipe" event from any reader connected, and checks the card against the stored hashes. However it needs to wrap the peripheral to actually write, plus the monitor nearby gives confirmation of a valid admin card. The monitor display text needs fixing to line wrap properly, but whatever. Hardware pics: Main area Door open Inside of door (lever keeps door closed if down, overriding cards) Some wiring/peripherals Another view of wiring. Heres the code: Code: 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 I'll probably edit this post tomorrow when i have time, and fix the text on the screen to look better.
Well edit post is broken, and i wanted to note that there's a computercraft bug where you may need to reconnect the peripherals from time to time by right clicking on the defective peripheral's modem twice.
I hope you have warded glass near to prevent the usage of enderpearls to get through the door. But nice nonetheless!
If i had the time, Id make the door solid and do one of those crazy piston contraptions. Keeps the mobs out at least. It doesn't do much for our base against players due to the numerous jet-pack exits in our ceilings.
You use the bundled cable functions in the redstone API. It works the same way redpower bundled cable does.
The reason I've done anything impractical. After some server trouble wiped the code from the computer (I could get it from the post), and the pistons disappeared, and the wired cable kept bugging out, Ive stopped using the computer system, and gone to a TC drawbridge and lever thing to close the "lobby" (where my enhanced portal is) off from the rest of my base.
I like your system of storing hashed passwords in the computer. Maybe in the future if you have more than one of these, you could use rednet to encrypt and send them to a master computer or server. That would be cool. I made a similar system, although it doesn't use passwords, but it uses security clearance levels (which are based off MJ12, a "secret police" in an old game's story) Each "agent" has a card listing their name & security level encrypted and decrypted using a master key. Each area in my compound that uses this system has a different required clearance, for example, level zero is Seraphic/8X, the command center is Throne/6G, etc. If someone with a greater or equal security clearance swipes their card in the door, it will open and greet them with a text to speech peripheral, "Welcome to (area), Agent (name)." New cards are made in the security office, requiring the base commander with Seraphic/8X clearance to create them. Each area has their own access log, including attempts to crash the system (flooding, in which case it simply reboots) Pretty pointless for a compound consisting of one person... but I had fun making it >__> Not going to release it yet, maybe after I completely finish it. Not trying to hijack your topic or anything. I'll put this somewhere else if you want, Legoman.
That sounds pretty cool. It sounds like it would be pretty hard for you to revoke a lost/stolen card's permissions it sounds like (since some of us like to pretend we have agents/employees/subjugates that need to go in and out all the time and might lose a card). I would have mine running to a master server if I hadn't been playing star-made so much recently. My base isn't complex enough (It consists of a power wing, an automation wing, and a manual crafting/monitoring room) for me to want to implement a multilevel permission system (yet), especially since I usually fly out the "jetpack entrance" rather than mucking about with the door .
Heh, honestly I didn't think of that. I might make a master-server system for storing users and their clearance levels..
You could use a player detector to detect if the player that is swiping the card matches the player the card belongs to.
It would be kind of a tossup between being realistic, yet still secure. They would still need the access card for it to work
Well, realistically if you stole a mag card from somebody it would open the door regardless of who you are. The mag cards on minecraft are more of a fun than secure thing imo.