Skip to content
This repository has been archived by the owner on Sep 19, 2020. It is now read-only.

Commit

Permalink
Added optional password login
Browse files Browse the repository at this point in the history
  • Loading branch information
oeed committed Dec 1, 2014
1 parent 33aed84 commit 22e5f14
Show file tree
Hide file tree
Showing 16 changed files with 345 additions and 25 deletions.
2 changes: 2 additions & 0 deletions Programs/Quest.program/startup
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ os.loadAPI('hash')
os.loadAPI('lQuery')

if OneOS then
OneOS.LoadAPI('/System/API/Hash.lua')
hash = Hash
OneOS.LoadAPI('/System/API/Wireless.lua')
OneOS.LoadAPI('/System/API/Peripheral.lua')
else
Expand Down
2 changes: 1 addition & 1 deletion System/.hash
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.99783031E8
1.86449353E9
31 changes: 30 additions & 1 deletion System/API/Bedrock.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
--Bedrock Build: 270
--Bedrock Build: 271
--This code is squished down in to one, rather hard to read file.
--As such it is not much good for anything other than being loaded as an API.
--If you want to look at the code to learn from it, copy parts or just take a look,
Expand Down Expand Up @@ -80,6 +80,35 @@ end
colours.transparent = 0
colors.transparent = 0
Filters = {
Greyscale = {
[colours.white] = colours.white,
[colours.orange] = colours.lightGrey,
[colours.magenta] = colours.lightGrey,
[colours.lightBlue] = colours.lightGrey,
[colours.yellow] = colours.lightGrey,
[colours.lime] = colours.lightGrey,
[colours.pink] = colours.lightGrey,
[colours.grey] = colours.grey,
[colours.lightGrey] = colours.lightGrey,
[colours.cyan] = colours.grey,
[colours.purple] = colours.grey,
[colours.blue] = colours.grey,
[colours.brown] = colours.grey,
[colours.green] = colours.grey,
[colours.red] = colours.grey,
[colours.transparent] = colours.transparent,
}
}
function FilterColour(colour, filter)
if filter[colour] then
return filter[colour]
else
return colours.black
end
end
DrawCharacters = function (x, y, characters, textColour, bgColour)
Drawing.WriteStringToBuffer(x, y, tostring(characters), textColour, bgColour)
end
Expand Down
1 change: 0 additions & 1 deletion System/API/Environment.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ GetCleanEnvironment = function(self)
for k, v in pairs(cleanEnvironment) do
cleanEnv[k] = v
end
cleanEnv._G = cleanEnv
return cleanEnv
end

Expand Down
2 changes: 0 additions & 2 deletions Programs/Quest.program/hash → System/API/Hash.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
-- Thanks to GravityScore for this!
-- http://www.computercraft.info/forums2/index.php?/topic/8169-sha-256-in-pure-lua/
--
-- This is used to hash passwords sent with the secure text field. It just reduces the chance of people getting hacked.
--

--
-- Adaptation of the Secure Hashing Algorithm (SHA-244/256)
Expand Down
9 changes: 9 additions & 0 deletions System/API/Settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ Defaults = {
Type = 'Side',
Label = 'Monitor Side',
Default = nil
},
Password = {
Type = 'Password',
Label = 'Password',
Default = nil
}
}
--[[
Expand Down Expand Up @@ -78,6 +83,10 @@ function GetValues(self)
return values
end

function CheckPassword(self, password)
return Hash.sha256(password) == self:GetValues()['Password']
end

DesktopColourChange = false
function SetDesktopColourChange(func)
DesktopColourChange = func
Expand Down
3 changes: 2 additions & 1 deletion System/Objects/CentrePoint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ UpdatePrograms = function(self)
Type = 'ProgramPreview',
Program = program,
OnClick = function(prv, event, side, x, y)
if not prv.Program.Hidden and ((x == 1 and y == 1) or side == 3) and prv.Program:Close() then
if not prv.Program.Hidden and ((x == 1 and y == 1) or side == 3) then
prv.Program:Close()
prv.Bedrock:GetObject('CentrePoint'):UpdatePrograms()
else
oldProgram = prv.Program
Expand Down
88 changes: 88 additions & 0 deletions System/Objects/LoginView.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
Inherit = 'View'
IsSleepMode = false

OnDraw = function(self, x, y)
for _y, row in ipairs(Drawing.Buffer) do
for _x, pixel in ipairs(row) do
Drawing.WriteToBuffer(_x, _y, pixel[1], Drawing.FilterColour(pixel[2], Drawing.Filters.Greyscale), Drawing.FilterColour(pixel[3], Drawing.Filters.Greyscale))
end
end
end

TryUnlock = function(self, password)
local secureTextBox = self:GetObject('SecureTextBox')
secureTextBox.Text = ''
if password ~= '' and Settings:CheckPassword(password) then
Log.i('Password correct, unlocking.')
self.Visible = false
self.Bedrock:SetActiveObject()
self:OnUnlock(self.IsSleepMode)
else
Log.i('Password incorrect.')
local label = self:GetObject('Label')
local secureStartX = secureTextBox.X
local labelStartX = label.X
local maxDelta = 4
local steps = {
-2,
-4,
-2,
0,
2,
4,
2,
0,
-1,
-2,
-1,
0,
1,
2,
1,
0
}
if Settings:GetValues()['UseAnimations'] then
self.Bedrock:SetActiveObject()
local i = 1
self.Bedrock:StartRepeatingTimer(function(newTimer)
secureTextBox.X = secureStartX + steps[i]
label.X = labelStartX + steps[i]
i = i + 1
if i > #steps then
self.Bedrock:StopTimer(newTimer)
self.Bedrock:SetActiveObject(secureTextBox)
end
end, 0.05)
end
end
end

Lock = function(self)
if Settings:GetValues()['Password'] == nil then
Log.i('No password, unlocking.')
self.Visible = false
if self.OnUnlock then
self:OnUnlock(self.IsSleepMode)
end
return
end
self.Visible = true

local secureTextBox = self:GetObject('SecureTextBox')
secureTextBox.OnChange = function(_self, event, keychar)
if keychar == keys.enter then
self:TryUnlock(secureTextBox.Text)
end
end
self.Bedrock:SetActiveObject(secureTextBox)

self:GetObject('ExitButton').OnClick = function(_self, event, side, x, y)
if self.IsSleepMode then
else
Shutdown(true)
end
end
end

OnClick = function(self, event, side, x, y)
end
40 changes: 35 additions & 5 deletions System/Programs/First Setup.program/Views/page5.view
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,54 @@
["Width"]="100%,-6",
["Name"]="Label",
["Type"]="Label",
["Text"]="All done! OneOS is now all setup and ready for you to use. Click 'Restart' to get going!\n\nIf the restart button does not work then hold Ctrl + R or break and replace your computer."
["Text"]="If you want a password enter it, otherwise leave the text box blank."
},
[3]={
["Y"]="9",
["X"]="25%",
["Width"]="50%",
["Name"]="PasswordTextBox",
["Type"]="SecureTextBox",
["Placeholder"]="Password",
["BackgroundColour"]=256,
["Active"]=true
},
[4]={
["Y"]="11",
["X"]="25%",
["Width"]="50%",
["Name"]="ConfirmPasswordTextBox",
["Type"]="SecureTextBox",
["Placeholder"]="Confirm Password",
["BackgroundColour"]=256,
},
[5]={
["Y"]="100%,-1",
["X"]="100%,-9",
["Name"]="RestartButton",
["X"]="100%,-7",
["Name"]="PasswordNextButton",
["Type"]="Button",
["Text"]="Restart",
["Text"]="Next",
["BackgroundColour"]=256
},
[4]={
[6]={
["Y"]="100%,-1",
["X"]="3",
["Name"]="BackButton",
["Type"]="Button",
["Text"]="Back",
["BackgroundColour"]=256
},
[7]={
["Y"]=13,
["X"]=3,
["Width"]="100%,-6",
["Name"]="NoMatchLabel",
["Type"]="Label",
["TextColour"]=16384,
["Align"]="Center",
["Text"]="Passwords do not match!",
["Visible"]=false
},
},
["BackgroundColour"]=1,
["ToolBarColour"] = 128,
Expand Down
38 changes: 38 additions & 0 deletions System/Programs/First Setup.program/Views/page6.view
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
["Children"]={
[1]={
["Y"]=1,
["X"]=1,
["Name"]="Toolbar",
["Type"]="View",
["InheritView"]="toolbar"
},
[2]={
["Y"]=5,
["X"]=3,
["Width"]="100%,-6",
["Name"]="Label",
["Type"]="Label",
["Text"]="All done! OneOS is now all setup and ready for you to use. Click 'Restart' to get going!\n\nIf the restart button does not work then hold Ctrl + R or break and replace your computer."
},
[3]={
["Y"]="100%,-1",
["X"]="100%,-9",
["Name"]="RestartButton",
["Type"]="Button",
["Text"]="Restart",
["BackgroundColour"]=256
},
[4]={
["Y"]="100%,-1",
["X"]="3",
["Name"]="BackButton",
["Type"]="Button",
["Text"]="Back",
["BackgroundColour"]=256
},
},
["BackgroundColour"]=1,
["ToolBarColour"] = 128,
["ToolBarTextColour"] = 1
}
22 changes: 20 additions & 2 deletions System/Programs/First Setup.program/startup
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
OneOS.LoadAPI('/System/API/Bedrock.lua', false)
OneOS.LoadAPI('/System/API/Hash.lua')

local program = Bedrock:Initialise()

Current = {
Page = 1,
ComputerName = nil,
DesktopColour = nil,
AnimationsEnabled = nil
AnimationsEnabled = nil,
Password = nil
}

function LoadCurrentView()
Expand Down Expand Up @@ -40,6 +42,21 @@ program:ObjectClick('NextButton', function(self, event, side, x, y)
LoadCurrentView()
end)

program:ObjectClick('PasswordNextButton', function(self, event, side, x, y)
if program:GetObject('PasswordTextBox').Text == '' then
Current.Password = nil
program:GetObject('NoMatchLabel').Visible = false
elseif program:GetObject('PasswordTextBox').Text == program:GetObject('ConfirmPasswordTextBox').Text then
Current.Password = Hash.sha256(program:GetObject('PasswordTextBox').Text)
program:GetObject('NoMatchLabel').Visible = false
else
program:GetObject('NoMatchLabel').Visible = true
return
end
Current.Page = Current.Page + 1
LoadCurrentView()
end)

program:ObjectClick('BackButton', function(self, event, side, x, y)
Current.Page = Current.Page - 1
LoadCurrentView()
Expand Down Expand Up @@ -67,7 +84,8 @@ program:ObjectClick('RestartButton', function(self, event, side, x, y)
local settings = {
ComputerName = Current.ComputerName,
DesktopColour = Current.DesktopColour,
UseAnimations = Current.AnimationsEnabled
UseAnimations = Current.AnimationsEnabled,
Password = Current.Password
}
os.setComputerLabel(settings.ComputerName)
h.write(textutils.serialize(settings))
Expand Down
Loading

0 comments on commit 22e5f14

Please sign in to comment.