Advertisement
RicardoLuis0

RedOS Login

Jul 29th, 2015
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.70 KB | None | 0 0
  1. os.pullEvent=os.pullEventRaw
  2. local function loadConfig(file)
  3.         local fConfig = fs.open(file, "r")
  4.         local ret = textutils.unserialize(fConfig.readAll())
  5.         fConfig.close()
  6.         return ret
  7. end
  8. local function saveConfig(table, file)
  9.         local fConfig = fs.open(file, "w") or error("Cannot open file "..file, 2)
  10.         fConfig.write(textutils.serialize(table))
  11.         fConfig.close()
  12. end
  13. term.clear()
  14. term.setCursorPos(1,1)
  15. if not fs.exists("login") then
  16. term.setTextColor(colors.red)
  17. print [[
  18. +-----------------------------------+
  19. |                                   |
  20. |                                   |
  21. |        Welcome to RedOS           |
  22. |                                   |
  23. | [ Press Any Key To Continue ]     |
  24. |                                   |
  25. |                                   |
  26. +-----------------------------------+
  27. ]]
  28. if os.pullEvent("key") ~= nil then
  29. term.clear()
  30. term.setCursorPos(1,1)
  31. print [[
  32. +-----------------------------------+
  33. |                                   |
  34. |                                   |
  35. |      User not Registered          |
  36. |                                   |
  37. | [ Press Any Key To Continue ]     |
  38. |                                   |
  39. |                                   |
  40. +-----------------------------------+
  41. ]]
  42. if os.pullEvent("key") ~= nil then
  43. term.clear()
  44. term.setCursorPos(1,1)
  45. print [[
  46. +-----------------------------------+
  47. |                                   |
  48. |                                   |
  49. | Choose Your Username              |
  50. |                                   |
  51. | Username:                         |
  52. |                                   |
  53. |                                   |
  54. +-----------------------------------+
  55. ]]
  56. term.setCursorPos(12,6)
  57. term.setTextColor(colors.white)
  58. user=read()
  59. term.clear()
  60. term.setTextColor(colors.red)
  61. term.setCursorPos(1,1)
  62. print [[
  63. +-----------------------------------+
  64. |                                   |
  65. |                                   |
  66. | Choose Your Password              |
  67. |                                   |
  68. | Password:                         |
  69. |                                   |
  70. |                                   |
  71. +-----------------------------------+
  72. ]]
  73. term.setCursorPos(12,6)
  74. term.setTextColor(colors.white)
  75. pass=read("*")
  76. term.clear()
  77. term.setTextColor(colors.red)
  78. term.setCursorPos(1,1)
  79. print [[
  80. +-----------------------------------+
  81. |                                   |
  82. |                                   |
  83. | Choose Your Name                  |
  84. |                                   |
  85. | Name:                             |
  86. |                                   |
  87. |                                   |
  88. +-----------------------------------+
  89. ]]
  90. term.setCursorPos(8,6)
  91. term.setTextColor(colors.white)
  92. name=read()
  93. saveConfig({user,pass,name},"login")
  94. term.clear()
  95. term.setTextColor(colors.red)
  96. term.setCursorPos(1,1)
  97. print [[
  98. +-----------------------------------+
  99. |                                   |
  100. |                                   |
  101. | Registering Sucessful             |
  102. |                                   |
  103. | Now Rebooting                     |
  104. |                                   |
  105. |                                   |
  106. +-----------------------------------+
  107. ]]
  108. os.sleep(1)
  109. os.reboot()
  110. end
  111. end
  112. end
  113. -- End
  114. login = loadConfig("login")
  115. term.setTextColor(colors.red)
  116. print [[
  117. +-----------------------------------+
  118. |                                   |
  119. |                                   |
  120. |        Welcome to RedOS           |
  121. |                                   |
  122. | [ Press Any Key To Continue ]     |
  123. |                                   |
  124. |                                   |
  125. +-----------------------------------+
  126. ]]
  127. if os.pullEvent("key") ~= nil then
  128. term.clear()
  129. term.setCursorPos(1,1)
  130. print [[
  131. +-----------------------------------+
  132. |                                   |
  133. |                                   |
  134. | Username:                         |
  135. |                                   |
  136. | Password:                         |
  137. |                                   |
  138. |                                   |
  139. +-----------------------------------+
  140. ]]
  141. term.setTextColor(colors.white)
  142. term.setCursorPos(12,4)
  143. username=read()
  144. term.setCursorPos(12,6)
  145. password=read("*")
  146. term.clear()
  147. term.setCursorPos(1,1)
  148. term.setTextColor(colors.red)
  149. if username == login[1] then
  150. if password == login[2] then
  151. print [[
  152. +-----------------------------------+
  153. |                                   |
  154. |                                   |
  155. |                                   |
  156. | Correct Password                  |
  157. |                                   |
  158. |                                   |
  159. |                                   |
  160. +-----------------------------------+
  161. ]]
  162. sleep(2)
  163. term.clear()
  164. term.setCursorPos(1,1)
  165. print("Welcome, "..login[3])
  166. print("Today is day "..os.day())
  167. shell.run("cmdline")
  168. else
  169. print [[
  170. +-----------------------------------+
  171. |                                   |
  172. |                                   |
  173. |                                   |
  174. | Wrong Password                    |
  175. |                                   |
  176. |                                   |
  177. |                                   |
  178. +-----------------------------------+
  179. ]]
  180. sleep(2)
  181. term.clear()
  182. sleep(1)
  183. os.reboot()
  184. end
  185. else
  186. print [[
  187. +-----------------------------------+
  188. |                                   |
  189. |                                   |
  190. |                                   |
  191. | Wrong Username                    |
  192. |                                   |
  193. |                                   |
  194. |                                   |
  195. +-----------------------------------+
  196. ]]
  197. sleep(2)
  198. term.clear()
  199. sleep(1)
  200. os.reboot()
  201. end
  202. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement