system/ui: add minimum WIFI password length validation (#35190)

* add minimum WIFI password length validation

* add min text size to keyboard

* disable enter if text size<min size

* add MAX_PASSWORD_LENGTH

* disable enter key

* set min_text_size for demo
pull/35191/head
Dean Lee 2 weeks ago committed by GitHub
parent 8c995ab26d
commit ce4fda1f92
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 8
      system/ui/widgets/keyboard.py
  2. 8
      system/ui/widgets/network.py

@ -45,9 +45,10 @@ keyboard_layouts = {
class Keyboard:
def __init__(self, max_text_size: int = 255):
def __init__(self, max_text_size: int = 255, min_text_size: int = 0):
self._layout = keyboard_layouts["lowercase"]
self._max_text_size = max_text_size
self._min_text_size = min_text_size
self._input_box = InputBox(max_text_size)
@property
@ -85,7 +86,8 @@ class Keyboard:
key_rect = rl.Rectangle(start_x, row_y_start + row * (key_height + v_space), new_width, key_height)
start_x += new_width
if gui_button(key_rect, key):
is_enabled = key != ENTER_KEY or len(self._input_box.text) >= self._min_text_size
if gui_button(key_rect, key, is_enabled=is_enabled):
if key == ENTER_KEY:
return 1
else:
@ -110,7 +112,7 @@ class Keyboard:
if __name__ == "__main__":
gui_app.init_window("Keyboard")
keyboard = Keyboard()
keyboard = Keyboard(min_text_size=8)
for _ in gui_app.render():
result = keyboard.render("Keyboard", "Type here")
if result == 1:

@ -11,6 +11,8 @@ from openpilot.system.ui.widgets.keyboard import Keyboard
from openpilot.system.ui.widgets.confirm_dialog import confirm_dialog
NM_DEVICE_STATE_NEED_AUTH = 60
MIN_PASSWORD_LENGTH = 8
MAX_PASSWORD_LENGTH = 64
ITEM_HEIGHT = 160
@ -46,7 +48,7 @@ class WifiManagerUI:
self.state: UIState = StateIdle()
self.btn_width = 200
self.scroll_panel = GuiScrollPanel()
self.keyboard = Keyboard()
self.keyboard = Keyboard(max_text_size=MAX_PASSWORD_LENGTH, min_text_size=MIN_PASSWORD_LENGTH)
self._networks: list[NetworkInfo] = []
@ -66,7 +68,9 @@ class WifiManagerUI:
if result == 1:
password = self.keyboard.text
self.keyboard.clear()
self.connect_to_network(network, password)
if len(password) >= MIN_PASSWORD_LENGTH:
self.connect_to_network(network, password)
elif result == 0:
self.state = StateIdle()

Loading…
Cancel
Save