From a6f1506f1a4f9dd9bfa65f01e535afcf60ada183 Mon Sep 17 00:00:00 2001 From: Kyle Evans Date: Tue, 27 Feb 2018 21:22:57 +0000 Subject: [PATCH] lualoader: Add a twiddle at password prompt This gives some form of feedback while typing, and matches-(ish*) Forth behavior. The cursor generally rests two column after the password prompt, then the twiddle is drawn three columns later and the cursor reset to resting position after being drawn. I've removed the note about re-evaluating it for security considerations and instead set it up as a module-local variable that we can set later depending on environment or something. It's set to false with no chance of changing at the moment. *As close as I can tell from reading check-password.4th, because I don't have an easy test (or deployed) setup for forth loader to check how close it is. Please do mention if it's not close enough. --- stand/lua/password.lua | 27 +++++++++++++++++++++++---- stand/lua/screen.lua | 18 ++++++++++++++++++ 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/stand/lua/password.lua b/stand/lua/password.lua index 124ce5686349..633c32d2e6df 100644 --- a/stand/lua/password.lua +++ b/stand/lua/password.lua @@ -33,27 +33,46 @@ local core = require("core") local screen = require("screen") local password = {} +-- Asterisks as a password mask +local show_password_mask = false +local twiddle_chars = {"/", "-", "\\", "|"} +local twiddle_pos = 1 -- Module exports function password.read() local str = "" local n = 0 + twiddle_pos = 1 + local function draw_twiddle() + loader.printc(" " .. twiddle_chars[twiddle_pos]) + screen.movecursor(-3, -1) + twiddle_pos = (twiddle_pos % #twiddle_chars) + 1 + end + + -- Space between the prompt and any on-screen feedback + loader.printc(" ") while true do local ch = io.getchar() if ch == core.KEY_ENTER then break end - -- XXX TODO: Evaluate if we really want this or not, as a - -- security consideration of sorts if ch == core.KEY_BACKSPACE or ch == core.KEY_DELETE then if n > 0 then n = n - 1 - -- loader.printc("\008 \008") + if show_password_mask then + loader.printc("\008 \008") + else + draw_twiddle() + end str = str:sub(1, n) end else - -- loader.printc("*") + if show_password_mask then + loader.printc("*") + else + draw_twiddle() + end str = str .. string.char(ch) n = n + 1 end diff --git a/stand/lua/screen.lua b/stand/lua/screen.lua index 7f883af8b440..a16f410764f6 100644 --- a/stand/lua/screen.lua +++ b/stand/lua/screen.lua @@ -49,6 +49,24 @@ function screen.setcursor(x, y) loader.printc("\027[" .. y .. ";" .. x .. "H") end +function screen.movecursor(dx, dy) + if core.isSerialBoot() then + return + end + + if dx < 0 then + loader.printc("\027[" .. -dx .. "D") + elseif dx > 0 then + loader.printc("\027[" .. dx .. "C") + end + + if dy < 0 then + loader.printc("\027[" .. -dy .. "A") + elseif dy > 0 then + loader.printc("\027[" .. dy .. "B") + end +end + function screen.setforeground(color_value) if color.disabled then return color_value