View difference between Paste ID: W4yTqrPH and n1wgDbe0
SHOW: | | - or go back to the newest paste.
1
local function readN(len, replaceChar)
2
  len = len or 12
3
  local input=""
4
  local key = 0
5
  term.setCursorBlink(true)
6
  repeat
7
    local e,p1 = os.pullEvent()
8
    if e=="char" then
9
      if #input < len then
10
        input = input .. p1
11
        term.write(replaceChar or p1)
12
      end
13
    elseif e=="key" and p1==keys.backspace and #input > 0 then
14
      input = input:sub(1,#input-1)
15
      local x,y = term.getCursorPos()
16
      term.setCursorPos(x-1,y)
17
      term.write(" ")
18
      term.setCursorPos(x-1,y)
19
    end
20
  until p1==keys.enter
21
  term.setCursorBlink(false)
22
  return input
23
end
24
25
sid = 0
26
lockdown = 0
27
actc = ""
28
actpw = ""
29
actpc = ""
30
userlog = ""
31
userpas = ""
32
puselog = ""
33
prog = 0
34
35
function clear()
36
term.clear()
37
term.setCursorPos(1,1)
38
end
39
40
function menu(id, text)
41
  if sid == id then
42
    write">> "
43
  else
44
    write"   "
45
  end
46
  print(text)
47
end
48
49
clear()
50
while prog == 0 do
51
os.pullEvent = os.pullEventRaw
52
rep1 = 0
53
rep2 = 0
54
rep3 = 0
55
rep4 = 0
56
rep5 = 0
57
rep6 = 0
58
ioerror = 0
59
term.setCursorPos(1, 12)
60
term.clearLine()
61
term.setCursorPos(1, 13)
62
term.clearLine()
63
term.setCursorPos(1, 14)
64
term.clearLine()
65
term.setCursorPos(1, 15)
66
term.clearLine()
67
term.setCursorPos(1, 16)
68
term.clearLine()
69
term.setCursorPos(1, 17)
70
term.clearLine()
71
term.setCursorPos(1,1)
72
print("|################################################|")
73
print("|              BOUTECH SYSTEM LOGIN              |")
74
print("|                OS Version : 1.3                |")
75
print("|################################################|")
76
term.setCursorPos(13,7)
77
print("|------------------------|")
78
term.setCursorPos(13,8)
79
print("|                        |")
80
term.setCursorPos(13,9)
81
print("|                        |")
82
term.setCursorPos(13,10)
83
print("|                        |")
84
term.setCursorPos(13,11)
85
print("|------------------------|")
86
term.setCursorPos(16,8)
87
menu(0, "Login")
88
term.setCursorPos(16,9)
89
menu(1, "Create Account")
90
term.setCursorPos(16,10)
91
menu(2, "Shutdown")
92
event, key = os.pullEvent("key")
93
94
if key == 200 then
95
  if sid == 0 then
96
    sid = sid+2
97
  elseif sid == 1 then
98
    sid = sid-1
99
  elseif sid == 2 then
100
    sid = sid-1
101
  end
102
elseif key == 208 then
103
  if sid == 2 then
104
    sid = sid-2
105
  elseif sid == 1 then
106
    sid = sid+1
107
  elseif sid == 0 then
108
    sid = sid+1
109
  end
110
elseif key == 28 then
111
  if sid == 0 then
112
    term.setCursorPos(13, 12)
113
    print("|   Enter Credentials.   |")
114
    term.setCursorPos(13, 13)
115
    print("|                        |")
116
    term.setCursorPos(13, 14)
117
    print("|                        |")
118
    term.setCursorPos(13, 15)
119
    print("|                        |")
120
    term.setCursorPos(13, 16)
121
    print("|                        |")
122
    term.setCursorPos(13, 17)
123
    print("|------------------------|")
124
    
125
    while rep5 == 0 do
126
      term.setCursorPos(1, 14)
127
      term.clearLine()
128
      term.setCursorPos(1, 16)
129
      term.clearLine()
130
      term.setCursorPos(13, 16)
131
      print("|                        |")
132
      term.setCursorPos(13, 14)
133
      print("|                        |")
134
      term.setCursorPos(15, 14)
135
      write("Username: ")
136
      userlog = readN()
137
      if userlog == "adminovrride" then
138
        rnd = math.random(100, 500)
139
        term.setCursorPos(1, 18)
140
        term.clearLine()
141
        term.setCursorPos (17, 18)
142
        print("Override Code: ".. rnd)
143
        apass = tostring((rnd + 11) * 83)
144
        term.setCursorPos(1, 16)
145
        term.clearLine()
146
        term.setCursorPos(13, 16)
147
        print("|                        |")
148
        term.setCursorPos(15, 16)
149
        write("Password: ")
150
        ovrpass = readN(12, "*")
151
        if ovrpass == apass then
152
          term.setCursorPos(1, 18)
153
          term.clearLine()
154
          term.setCursorPos(15, 18)
155
          print("Override Successful...")
156
          sleep(3)
157
          term.clear()
158
          term.setCursorPos(1, 1)
159
          rep5 = rep5+1
160
          rep6 = rep6+1
161
          prog = prog+1
162
        else
163
          term.setCursorPos(1, 18)
164
          term.clearLine()
165
          term.setCursorPos(15, 18)
166
          print("  Override Failed...")
167
          sleep(1)
168
          rep5 = rep5+1
169
          rep6 = rep6+1
170
          sid = 0
171
        end
172
      else      
173
        if userlog == "" then
174
          term.setCursorPos(1, 18)
175
          term.clearLine()
176
          term.setCursorPos(18, 18)
177
          print("Invalid Username")
178
          sleep(1)
179
          ioerror = ioerror+1
180
          if ioerror == 3 then
181
            rep5 = rep5+1
182
            rep6 = rep6+1
183
            sid = 0
184
          else
185
          end
186
        else
187
          ioerror = 0
188
          ulog = fs.exists("users/".. userlog)
189
          if ulog == true then
190
            term.setCursorPos(1, 16)
191
            term.clearLine()
192
            term.setCursorPos(13, 16)
193
            print("|                        |")
194
            term.setCursorPos(15, 16)
195
            write("Password: ")
196
            userpas = readN(12, "*")
197
            if userpas == "" then
198
              term.setCursorPos(1, 18)
199
              term.clearLine()
200
              term.setCursorPos(15, 18)
201
              print("Invalid Password Entry")
202
              sleep(1)
203
              ioerror = ioerror+1
204
              term.setCursorPos(1, 18)
205
              term.clearLine()
206
              if ioerror == 3 then
207
                rep5 = rep5+1
208
                sid = 0
209
              else
210
              end
211
            else
212
              ulog = io.open("users/".. userlog, "r") or nil
213
              pass = ulog and ulog:read()
214
              ulog:close()
215
              if (pass and pass==userpas) then
216
                term.setCursorPos(1, 18)
217
                term.clearLine()
218
                term.setCursorPos(16, 18)
219
                print("  Login Success...")
220
                currentw = fs.open("current", "w")
221
                accessr = fs.open("users/".. userlog, "r")
222
                accessl = accessr.readLine() and accessr.readLine()
223
                currentw.writeLine(userlog)
224
                currentw.writeLine(accessl)
225
                currentw.close()
226
                accessr.close()
227
                rep5 = rep5+1
228
                rep6 = rep6+1
229
                prog = prog+1
230
                sid = 0
231
                sleep(2)
232
                shell.run("system")
233
              else
234
                if lockdown < 2 then
235
                  term.setCursorPos(1, 18)
236
                  term.clearLine()
237
                  term.setCursorPos(16, 18)
238
                  print("   Wrong Password")
239
                  sleep(1)
240
                  if userlog == puselog then
241
                    lockdown = lockdown+1                    
242
                  else
243
                    lockdown = 0
244
                    puselog = userlog
245
                    lockdown = lockdown+1
246
                  end
247
                else
248
                  while rep6 == 0 do
249
                    term.setCursorPos(15, 18)
250
                    rnd = tostring(math.random(101, 999))
251
                    if not fs.exists("pending/".. rnd) then
252
                      fs.move("users/".. userlog, "pending/".. rnd)
253
                      term.setCursorPos(1, 18)
254
                      term.clearLine()
255
                      term.setCursorPos(15, 18)
256
                      print(" Lockdown Ref #: "..rnd)
257
                      sleep(1)
258
                      ulog = fs.open("pending/".. rnd, "a")
259
                      ulog.writeLine("Username: ".. userlog)
260
                      ulog.close()
261
                      rep6 = rep6+1
262
                      rep5 = rep5+1
263
                      sid = 0
264
                    else
265
                    end
266
                  end
267
                end 
268
              end
269
            end
270
          else
271
            term.setCursorPos(14, 18)
272
            print("  Bad/Unknown Username")
273
            sleep(1)
274
          end
275
        end 
276
      end
277
    end
278
  elseif sid == 1 then
279
    term.setCursorPos(13, 12)
280
    print("|  Submit Account Info.  |")
281
    term.setCursorPos(13, 13)
282
    print("|                        |")
283
    term.setCursorPos(13, 14)
284
    print("|                        |")
285
    term.setCursorPos(13, 15)
286
    print("|                        |")
287
    term.setCursorPos(13, 16)
288
    print("|                        |")
289
    term.setCursorPos(13, 17)
290
    print("|------------------------|")
291
        
292
    while rep1 == 0 do
293
      term.setCursorPos(1, 14)
294
      term.clearLine()
295
      term.setCursorPos(13, 14)
296
      print("|                        |")
297
      term.setCursorPos(15, 14)
298
      write("Username: ")
299
      input = readN()
300
      actc = input
301
      actex = fs.exists("users/".. actc)
302
      if input == "adminovrride" then
303
        term.setCursorPos(1, 18)
304
        term.clearLine()
305
        term.setCursorPos(18, 18)
306
        print("Invalid Username")
307
        sleep(1)
308
        ioerror = ioerror+1
309
        if ioerror == 3 then
310
          rep1 = 1
311
          rep2 = 1
312
          rep3 = 1
313
          sid = 0
314
        else
315
        end
316
      else
317
        if input == "" then
318
          term.setCursorPos(1, 18)
319
          term.clearLine()
320
          term.setCursorPos(18, 18)
321
          print("Invalid Username")
322
          sleep(1)
323
          ioerror = ioerror+1
324
          if ioerror == 3 then
325
            rep1 = 1
326
            rep2 = 1
327
            rep3 = 1
328
            sid = 0
329
          else
330
          end
331
        elseif actex == true then
332
          term.setCursorPos(1, 18)
333
          term.clearLine()
334
          term.setCursorPos(15, 18)
335
          print (" Username Unavailable")
336
          sleep(1)
337
        else
338
          ioerror = 0
339
          rep1 = 1
340
        end
341
      end
342
    end
343
    
344
    while rep2 == 0 do
345
      while rep3 == 0 do
346
        term.setCursorPos(15, 15)
347
        write("Password: ")
348
        input = readN(12, "*")
349
        if input == "" then
350
          term.setCursorPos(1, 18)
351
          term.clearLine()
352
          term.setCursorPos(15, 18)
353
          print("Invalid Password Entry")
354
          sleep(1)
355
          ioerror = ioerror+1
356
          if ioerror == 3 then
357
            rep1 = 1
358
            rep2 = 1
359
            rep3 = 1
360
          else
361
          end
362
        else
363
          ioerror = 0
364
          actpw = input
365
          rep3 = 1
366
          rep2 = 1
367
        end
368
      end
369
      
370
      term.setCursorPos(13, 16)
371
      print("|                        |")
372
      term.setCursorPos(15, 16)
373
      write("Confirm : ")
374
      input = readN(12, "*")
375
      actpc = input
376
      if (actpc) == (actpw) then
377
        while rep4 == 0 do
378
          rnd = tostring(math.random(1011, 9999))
379
          if not fs.exists("pending/".. rnd) then
380
            file = fs.open("pending/".. rnd, "w")
381
            file.writeLine("actc")
382
            file.writeLine("actpw")
383
            file.close()
384
            rep4 = rep4+1
385
          else
386
          end
387
        end
388
        term.setCursorPos(1, 18)
389
        term.clearLine()
390
        term.setCursorPos(13, 18)
391
        print("  Pending... Ref #: ", rnd)
392
        sleep(1)
393
        ioerror = 0
394
        rep2 = 1
395
        sid = 0
396
      else
397
        term.setCursorPos(1, 18)
398
        term.clearLine()
399
        term.setCursorPos(15, 18)
400
        print("Password Doesn't Match")
401
        sleep(1)
402
        rep2 = 0
403
        ioerror = ioerror+1
404
        if ioerror == 3 then
405
          rep1 = 1
406
          rep2 = 1
407
          rep3 = 1
408
        else
409
        end
410
      end
411
    end
412
    
413
  elseif sid == 2 then
414
    term.setCursorPos(13,14)
415
    print("|########################|")
416
    term.setCursorPos(13,15)
417
    print("# SYSTEM SHUTTING DOWN!! #")
418
    term.setCursorPos(13,16)
419
    print("|########################|")
420
    sleep(3)
421
    os.shutdown()
422
    end
423
  end
424
end