Skip to content
Snippets Groups Projects
Commit 0a1f3f25 authored by Leon Tappe's avatar Leon Tappe 🔥
Browse files

properly enforce password and username restrictions

parent 41f6bf49
No related branches found
No related tags found
No related merge requests found
......@@ -54,9 +54,13 @@ class _RegisterPageState extends State<RegisterPage> {
decoration: InputDecoration(
labelText: 'Passwort',
suffix: IconButton(
icon: Icon(Icons.remove_red_eye_rounded,
color: _showPassword ? primary : darkGrey),
onPressed: () => setState(() => _showPassword = !_showPassword),
icon: Icon(
Icons.remove_red_eye_rounded,
color: _showPassword ? secondary : darkGrey,
),
constraints: const BoxConstraints(maxWidth: 24.0),
padding: EdgeInsets.zero,
),
),
onChanged: (String input) => setState(() => _password = input),
......@@ -121,6 +125,6 @@ class _RegisterPageState extends State<RegisterPage> {
if (empty != null) {
return empty;
}
return input!.length > 5 ? null : 'Das Passwort muss mindestens 6 Zeichen enthalten';
return input!.length > 4 ? null : 'Das Passwort muss mindestens 5 Zeichen enthalten';
}
}
......@@ -28,6 +28,8 @@ class _UserDialogState extends State<UserDialog> {
bool _showPassword = false;
final GlobalKey<FormState> _formKey = GlobalKey();
@override
Widget build(BuildContext context) {
return ContentDialog(
......@@ -36,12 +38,15 @@ class _UserDialogState extends State<UserDialog> {
Padding(
padding: const EdgeInsets.only(bottom: 8.0),
child: Form(
key: _formKey,
child: Column(
children: [
TextFormField(
decoration: const InputDecoration(labelText: 'Nutzername'),
onChanged: (String input) => _user!.username = input,
controller: TextEditingController(text: _user!.username),
validator: (String? input) =>
input == null || input.isEmpty ? 'Pflichtfeld' : null,
),
if (widget.user == null)
TextFormField(
......@@ -59,6 +64,11 @@ class _UserDialogState extends State<UserDialog> {
),
onChanged: (String input) => _password = input,
controller: TextEditingController(text: _password ?? ''),
validator: (String? input) => (input?.length ?? 0) < 5
? 'Das Passwort muss mindestens 5 Zeichen enthalten'
: input == null || input.isEmpty
? 'Pflichtfeld'
: null,
obscureText: !_showPassword,
),
TextFormField(
......@@ -95,8 +105,11 @@ class _UserDialogState extends State<UserDialog> {
child: const Text('Abbrechen'),
),
ElevatedButton(
onPressed: () =>
Navigator.of(context).pop(UserResult(save: true, user: _user, password: _password)),
onPressed: () {
if (_formKey.currentState?.validate() ?? false) {
Navigator.of(context).pop(UserResult(save: true, user: _user, password: _password));
}
},
child: const Text('Speichern'),
),
],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment