Make sure the wifi password adheres to the hostapd rules

This commit is contained in:
Ana Custura 2026-03-12 10:55:02 +00:00
parent e79969805d
commit 3d83c96586
3 changed files with 9 additions and 4 deletions

View file

@ -12,6 +12,11 @@ def hostname_check(form, field):
if not matches:
raise ValidationError(_l('Only dashes, underscores, letters and numbers allowed'))
def wifi_length_check(form, field):
if len(field.data) > 63:
raise ValidationError('Wifi password cannot be longer than 63 characters.')
if len(field.data) in range(1,9):
raise ValidationError('Wifi password cannot be shorter than 8 characters.')
class LoginForm(FlaskForm):
username = StringField(_l('Username'), validators=[DataRequired()])
@ -23,7 +28,7 @@ class LoginForm(FlaskForm):
class SettingsForm(FlaskForm):
# Access point settings
ssid = StringField(_l('SSID'), validators=[DataRequired(), Length(1, 64), hostname_check])
wifi_password = StringField(_l('WiFi Password'), validators=[Length(0, 64)])
wifi_password = StringField(_l('WiFi Password'), validators=[wifi_length_check])
enable_access_point = BooleanField(_l('Enable Access Point'))
# Customisation settings
butterbox_name = StringField(_l('Butterbox Name'), validators=[DataRequired()])