sanovskiy

Mag cards

May 10th, 2016
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. os.loadAPI("SHA")
  2. os.pullEvent = os.pullEventRaw
  3.  
  4. redstone.setBundledOutput("left", colors.white)
  5. math.randomseed(os.time())
  6.  
  7. term.clear()
  8. term.setCursorPos(1,1)
  9. print("Legoman Technologies door lock V1.0")
  10. print("Thank you to tomas1666 for his SHA1 code")
  11.  
  12. modem = peripheral.wrap("top")
  13.  
  14. if modem == nil then
  15. error("Modem not on top")
  16. end
  17.  
  18. if modem.isPresentRemote("mag card reader_0") then
  19. reader = peripheral.wrap("mag card reader_0")
  20. print("Card reader connected")
  21. else
  22. error("Mag-card reader not found")
  23. end
  24.  
  25. if modem.isPresentRemote("monitor_0") then
  26. monitor = peripheral.wrap("monitor_0")
  27. print("Monitor connected")
  28. else
  29. error("Monitor not found")
  30. end
  31.  
  32. hashedPw = "Put the hashed admin password here"
  33. cardsFilePath = "Cards"
  34. cards = {""}
  35. 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", "@", "#", "$", "%", "&", "?"}
  36. newpass = ""
  37. cardNum = 0
  38.  
  39. if fs.exists(cardsFilePath) then
  40. cardsFile = fs.open(cardsFilePath, "r")
  41. cards = textutils.unserialize(cardsFile.readAll())
  42. cardsFile.close()
  43. end
  44.  
  45. while true do
  46. admin = false
  47.  
  48. monitor.clear()
  49. monitor.setCursorPos(1,1)
  50. monitor.write("Welcome to Legoman Industries! Please insert a card!")
  51. reader.setInsertCardLight(true)
  52.  
  53.  
  54. event, p1,p2,p3 = os.pullEvent()
  55.  
  56. if event == "mag_swipe" then
  57. if SHA.SHA1_2(p1) == hashedPw then
  58. admin = true
  59. end
  60. for x = 1, #cards do
  61. if SHA.SHA1_2(p1) == cards[x] then
  62. reader.setInsertCardLight(false)
  63. redstone.setBundledOutput("left", 0)
  64. os.sleep(3)
  65. redstone.setBundledOutput("left", colors.white)
  66. reader.setInsertCardLight(true)
  67. break
  68. end
  69. end
  70. end
  71. if admin == true then
  72. reader.setInsertCardLight(false)
  73. monitor.clear()
  74. monitor.setCursorPos(1,1)
  75. monitor.write("Admin granted! Insert blank card!")
  76. for z = 1,15 do
  77. case = math.random(1,2) -- randomly choose case (caps or lower)
  78. a = math.random(1,#chars) -- randomly choose a character from the "char" array
  79. if case == 1 then
  80. x=string.upper(chars[a]) -- uppercase if case = 1
  81. elseif case == 2 then
  82. x=string.lower(chars[a]) -- lowercase if case = 2
  83. end
  84. newpass = newpass..x
  85. end
  86. reader.setInsertCardLight(true)
  87. cardNum = #cards
  88. print(reader.beginWrite(newpass, cardNum..""))
  89. table.insert(cards, SHA.SHA1_2(newpass))
  90.  
  91. while reader.isWaiting() do
  92. end
  93.  
  94. reader.setInsertCardLight(false)
  95. monitor.clear()
  96. monitor.setCursorPos(1,1)
  97. monitor.write("New card created!")
  98. newpass = ""
  99. end
  100.  
  101. os.sleep(1)
  102.  
  103. cardsFile = fs.open(cardsFilePath, "w")
  104. cardsFile.write(textutils.serialize(cards))
  105. cardsFile.close()
  106.  
  107.  
  108. end
Add Comment
Please, Sign In to add comment