-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlock.lua
More file actions
75 lines (70 loc) · 1.69 KB
/
lock.lua
File metadata and controls
75 lines (70 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
-- Written by Tuhkis1
local pullevent = os.pullEvent
os.pullEvent = os.pullEventRaw
local w, h = term.getSize()
local instruction = 'Type your password.'
local y_middle = h * 0.5
local guess = ''
local run = true
-- get password
local password
local f = fs.open('/.passwd', 'r')
if f == nil then
print('No password set in ".passwd"')
print('Press a key to continue...')
read()
run = false
else
password = f.readLine()
f.close()
if #password > 64 then
print('Dangerously long password. A password cannot be longer than 64 characters.')
print('Press a key to continue...')
read()
run = false
end
end
-- get splash text.
local splash = 'lock by Tuhkis'
if fs.exists('.locksplash') then
f = fs.open('.locksplash', 'r')
splash = f.readLine()
f.close()
end
while run do
term.clear()
term.setCursorPos(w * 0.5 - #instruction * 0.5, y_middle)
term.setTextColor(colors.yellow)
term.write(instruction)
term.setCursorPos(w * 0.5 - #guess * 0.5, y_middle + 1)
term.setTextColor(colors.lightBlue)
for i = 1, #guess do
term.write('*')
end
term.setCursorPos(w * 0.5 - #splash * 0.5, y_middle - 2)
term.setTextColor(colors.green)
term.write(splash)
local e, c = os.pullEvent('key')
if c == keys.backspace and guess ~= '' then
guess = guess:sub(1, -2)
elseif c == keys.enter then
if guess == password then
run = false
break
else
guess = ''
end
else
local e1, c1 = os.pullEvent('char')
-- should be true no matter what, but apparantly isn't. :shrug:
if e1 == 'char' then
if #guess < 64 then
guess = guess .. c1
end
end
end
end
term.clear()
term.setCursorPos(1, 1)
term.setTextColor(colors.white)
-- EOF