ComputerCraft Archive

security

computer utility kepler155c github

Description

ComputerCraft OS

Installation

Copy one of these commands into your ComputerCraft terminal:

wget:wget https://raw.githubusercontent.com/kepler155c/opus/develop-1.8/sys/modules/opus/security.lua security
Archive:wget https://cc.shobie.xyz/cc/get/gh-kepler155c-opus-sys-modules-opus-security security
Quick Install: wget https://cc.shobie.xyz/cc/get/gh-kepler155c-opus-sys-modules-opus-security security

Usage

Run: security

Tags

none

Source

View Original Source

Code Preview

local Config = require('opus.config')

local Security = { }

function Security.verifyPassword(password)
	local current = Security.getPassword()
	return current and password == current
end

function Security.hasPassword()
	return not not Security.getPassword()
end

function Security.getIdentifier()
	local config = Config.load('os')

	if not config.identifier then
		local key = { }
		for _ = 1, 32 do
			table.insert(key, ("%02x"):format(math.random(0, 0xFF)))
		end
		config.identifier = table.concat(key)

		Config.update('os', config)
	end

	return config.identifier
end

function Security.updatePassword(password)
	local config = Config.load('os')
	config.password = password
	Config.update('os', config)
end

function Security.getPassword()
	return Config.load('os').password
end

return Security