Update settings.lua

This commit is contained in:
Ale32bit 2015-09-21 21:34:35 +02:00
parent e09a479e1d
commit fd8e55e92b

View file

@ -1,3 +1,6 @@
local pwChange
local pwChangeRep
local menu = { local menu = {
"Update", "Update",
"Change PIN", "Change PIN",
@ -13,7 +16,7 @@ end
local function header() local function header()
clear() clear()
local w, h = term.getSize() local w, h = term.getSize()
paintutils.drawLine(1,1,w,1, colors.gray) paintutils.drawLine(1,1,w,1, colors.blue)
term.setTextColor(colors.white) term.setTextColor(colors.white)
term.setCursorPos(1,1) term.setCursorPos(1,1)
write(" "..sPhone.user) write(" "..sPhone.user)
@ -28,7 +31,7 @@ local function changePassword()
term.setCursorPos(1,1) term.setCursorPos(1,1)
paintutils.drawImage(paintutils.loadImage("/.sPhone/interfaces/login"),1,1) paintutils.drawImage(paintutils.loadImage("/.sPhone/interfaces/login"),1,1)
term.setTextColor(colors.white) term.setTextColor(colors.white)
term.setBackgroundColor(colors.gray) term.setBackgroundColor(colors.blue)
term.setCursorPos(1,1) term.setCursorPos(1,1)
write(" "..sPhone.user) write(" "..sPhone.user)
if sPhone.wrongPassword then if sPhone.wrongPassword then
@ -39,22 +42,14 @@ local function changePassword()
term.setTextColor(colors.black) term.setTextColor(colors.black)
term.setBackgroundColor(colors.white) term.setBackgroundColor(colors.white)
sertextext.center(7," Current Password") sertextext.center(7," Current Password")
local loginTerm = window.create(term.native(), 8,10,12,1, true)
term.redirect(loginTerm)
term.setBackgroundColor(colors.white)
term.clear()
term.setCursorPos(1,1)
term.setTextColor(colors.black) term.setTextColor(colors.black)
term.setCursorBlink(true) local password = read("*")
term.setCursorPos(9,10) term.redirect(sPhone.mainTerm)
local _, k1 = os.pullEvent("char")
write("*")
term.setCursorPos(12,10)
local _, k2 = os.pullEvent("char")
write("*")
term.setCursorPos(15,10)
local _, k3 = os.pullEvent("char")
write("*")
term.setCursorPos(18,10)
local _, k4 = os.pullEvent("char")
write("*")
term.setCursorBlink(false)
local password = k1..k2..k3..k4
local fpw = fs.open("/.sPhone/.password","r") local fpw = fs.open("/.sPhone/.password","r")
if sha256.sha256(password) ~= fpw.readLine() then if sha256.sha256(password) ~= fpw.readLine() then
sPhone.wrongPassword = true sPhone.wrongPassword = true
@ -71,7 +66,7 @@ local function changePassword()
term.setCursorPos(1,1) term.setCursorPos(1,1)
paintutils.drawImage(paintutils.loadImage("/.sPhone/interfaces/login"),1,1) paintutils.drawImage(paintutils.loadImage("/.sPhone/interfaces/login"),1,1)
term.setTextColor(colors.white) term.setTextColor(colors.white)
term.setBackgroundColor(colors.gray) term.setBackgroundColor(colors.blue)
term.setCursorPos(1,1) term.setCursorPos(1,1)
write(" "..sPhone.user) write(" "..sPhone.user)
if sPhone.wrongPassword then if sPhone.wrongPassword then
@ -82,49 +77,33 @@ local function changePassword()
term.setTextColor(colors.black) term.setTextColor(colors.black)
term.setBackgroundColor(colors.white) term.setBackgroundColor(colors.white)
sertextext.center(7," New Password") sertextext.center(7," New Password")
local loginTerm = window.create(term.native(), 8,10,12,1, true)
term.redirect(loginTerm)
term.setBackgroundColor(colors.white)
term.clear()
term.setCursorPos(1,1)
term.setTextColor(colors.black) term.setTextColor(colors.black)
term.setCursorBlink(true) pwChange = read("*")
term.setCursorPos(9,10) term.redirect(sPhone.mainTerm)
local _, k1 = os.pullEvent("char")
write("*")
term.setCursorPos(12,10)
local _, k2 = os.pullEvent("char")
write("*")
term.setCursorPos(15,10)
local _, k3 = os.pullEvent("char")
write("*")
term.setCursorPos(18,10)
local _, k4 = os.pullEvent("char")
write("*")
term.setCursorBlink(false)
local pwChange = k1..k2..k3..k4
term.clear() term.clear()
term.setCursorPos(1,1) term.setCursorPos(1,1)
paintutils.drawImage(paintutils.loadImage("/.sPhone/interfaces/login"),1,1) paintutils.drawImage(paintutils.loadImage("/.sPhone/interfaces/login"),1,1)
term.setTextColor(colors.white) term.setTextColor(colors.white)
term.setBackgroundColor(colors.gray) term.setBackgroundColor(colors.blue)
term.setCursorPos(1,1) term.setCursorPos(1,1)
write(" "..sPhone.user) write(" "..sPhone.user)
term.setTextColor(colors.black) term.setTextColor(colors.black)
term.setBackgroundColor(colors.white) term.setBackgroundColor(colors.white)
sertextext.center(7," Repeat Password") sertextext.center(7," Repeat Password")
local loginTerm = window.create(term.native(), 8,10,12,1, true)
term.redirect(loginTerm)
term.setBackgroundColor(colors.white)
term.clear()
term.setCursorPos(1,1)
term.setTextColor(colors.black) term.setTextColor(colors.black)
term.setCursorBlink(true) pwChangeRep = read("*")
term.setCursorPos(9,10) term.redirect(sPhone.mainTerm)
local _, r1 = os.pullEvent("char")
write("*")
term.setCursorPos(12,10)
local _, r2 = os.pullEvent("char")
write("*")
term.setCursorPos(15,10)
local _, r3 = os.pullEvent("char")
write("*")
term.setCursorPos(18,10)
local _, r4 = os.pullEvent("char")
write("*")
term.setCursorBlink(false)
pwChangeRep = r1..r2..r3..r4
if sha256.sha256(pwChange) ~= sha256.sha256(pwChangeRep) then if sha256.sha256(pwChange) ~= sha256.sha256(pwChangeRep) then
sPhone.wrongPassword = true sPhone.wrongPassword = true
@ -150,7 +129,7 @@ local w, h = term.getSize()
local function redraw() local function redraw()
clear() clear()
local w, h = term.getSize() local w, h = term.getSize()
paintutils.drawLine(1,1,w,1, colors.gray) paintutils.drawLine(1,1,w,1, colors.blue)
term.setTextColor(colors.white) term.setTextColor(colors.white)
term.setCursorPos(2,1) term.setCursorPos(2,1)
write(sPhone.user) write(sPhone.user)
@ -164,7 +143,7 @@ local function redraw()
while true do while true do
redraw() redraw()
local name, id = ui.menu(menu, "Settings",true) local name, id = sPhone.menu(menu, "Settings",true)
if id == 0 then if id == 0 then
return return
elseif id == 1 then elseif id == 1 then