From 6687bc8fced2d5bbfec79d5d908f13448dd1e732 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Tue, 12 Jan 2016 03:42:21 +0100 Subject: forms: Try to disable autocomplete on forms with password fields By default browsers (at least chrome is very agressive) try to detect forms with password inputs and try to insert saved passwords (for example from the login page). The default attribute to disable this (autocomplete=off) is ignored sometimes. Therefore we add two hidden input fields, that disable the auto filling at least in chrome. --- utils/widgets.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'utils/widgets.py') diff --git a/utils/widgets.py b/utils/widgets.py index 3b65b82..4ce206f 100644 --- a/utils/widgets.py +++ b/utils/widgets.py @@ -20,3 +20,15 @@ class TextArea(wtforms.widgets.core.TextArea): if arg not in kwargs: kwargs[arg] = self.kwargs[arg] return super(TextArea, self).__call__(field, **kwargs) + + +class PasswordInput(wtforms.widgets.core.PasswordInput): + def __init__(self, hide_value=True, **kwargs): + self.kwargs = kwargs + super(PasswordInput, self).__init__(hide_value) + + def __call__(self, field, **kwargs): + for arg in self.kwargs: + if arg not in kwargs: + kwargs[arg] = self.kwargs[arg] + return super(PasswordInput, self).__call__(field, **kwargs) -- cgit v1.2.3-1-g7c22