Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- by morganamilo ([email protected])
- --to add to startup run this program in startup (shell.run('file name'))
- --or name this file startup
- --usernames = the file name at /users/
- --passwords is data in the file (hashed)
- --downloads my hash program if not on pc
- --'ProgramName user1 pass1' creates an account on the turtle with
- --username: user1
- --password: pass1
- if fs.exists('/hash') == false then
- print('no hash program found, downloading...')
- shell.run('pastebin get VPuGKaBy /hash')
- end
- local oldPull = os.pullEvent
- os.pullEvent = os.pullEventRaw
- os.loadAPI('/hash')
- if fs.exists('/users/') == false then
- shell.run('mkdir /users/')
- end
- local args = {...}
- if args[1] ~= 'new' and args[1] ~= 'delete' and args[1] ~= 'login' and args[1] ~= nil then
- local name = shell.getRunningProgram()
- print('Usages:\n' .. name .. ' login\n' .. name.. ' new <username> <password>\n' .. name .. ' delete <username>')
- error()
- end
- function logIn()
- local pass
- if fs.list('/users/')[1] == null and (args[1] == 'login' or args[1] == nil) then
- print('cant begin login, no accounts exis')
- local name = shell.getRunningProgram()
- print('Usages:\n' .. name .. ' login\n' .. name.. ' new <username> <password>\n' .. name .. ' delete <username>')
- os.pullEvent = oldPull
- error()
- end
- while true do
- io.write('username: ')
- local inUser = read()
- io.write('password: ')
- local inPass = read('*')
- if inPass ~= '' then
- inPass = hash.sha256(inPass)
- end
- local empty = ""
- if inUser ~= empty and inPass ~= empty and fs.exists('/users/' .. inUser) then
- local userFile = fs.open('/users/' .. inUser, 'r')
- pass = userFile.readAll()
- userFile.close()
- end
- if pass == inPass then
- break
- else
- print('username or password is incorrect\n')
- inPass = empty
- inUser = empty
- end
- end
- term.clear()
- term.setCursorPos(1, 1)
- print('Welcome')
- end
- function newUser(user, pass)
- if fs.exists('/users/' .. user) then
- print('user already exists')
- else
- local userFile = fs.open('/users/' .. user, 'w')
- pass = hash.sha256(pass)
- userFile.write(pass)
- userFile.close()
- end
- end
- function deleteUser(user)
- if fs.exists('/users/' .. user) ~= true then
- print('user doesnt exist')
- else
- fs.delete('/users/' .. user)
- print('done\n')
- end
- end
- if args[1] == 'new' and args[3] ~= nil then
- newUser(args[2],args[3])
- elseif args[1] == 'login' or args[1] == nil then
- logIn()
- elseif args[1] == 'delete' and args[2] ~= nil then
- deleteUser(args[2])
- end
- os.unloadAPI('/hash')
- os.pullEvent = oldPull
Advertisement
Add Comment
Please, Sign In to add comment