Adding the ability to configure password strength in the local_settings. Fixes bug 948317
Change-Id: I96e3838ab6675e7282172e56be3f0359065caccb
This commit is contained in:
parent
e165416a12
commit
24f6bc59b2
1
AUTHORS
1
AUTHORS
@ -23,6 +23,7 @@ Jay Pipes <jaypipes@gmail.com>
|
||||
Jeffrey Wilcox <jeffjapan@gmail.com>
|
||||
Jesse Andrews <anotherjesse@gmail.com>
|
||||
Jim Yeh <lemonlatte@gmail.com>
|
||||
John Postlethwait <john.postlethwait@nebula.com>
|
||||
Joseph Heck <heckj@mac.com>
|
||||
Joshua McKenty <joshua@pistoncloud.com>
|
||||
Julien Danjou <julien.danjou@enovance.com>
|
||||
|
@ -28,6 +28,7 @@ from django.forms import ValidationError
|
||||
from horizon import api
|
||||
from horizon import exceptions
|
||||
from horizon import forms
|
||||
from horizon.utils import validators
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
@ -61,10 +62,14 @@ class BaseUserForm(forms.SelfHandlingForm):
|
||||
class CreateUserForm(BaseUserForm):
|
||||
name = forms.CharField(label=_("Name"))
|
||||
email = forms.EmailField(label=_("Email"))
|
||||
password = forms.CharField(label=_("Password"),
|
||||
widget=forms.PasswordInput(render_value=False))
|
||||
password = forms.RegexField(
|
||||
label=_("Password"),
|
||||
widget=forms.PasswordInput(render_value=False),
|
||||
regex=validators.password_validator(),
|
||||
error_messages={'invalid': validators.password_validator_msg()})
|
||||
confirm_password = forms.CharField(
|
||||
label=_("Confirm Password"),
|
||||
required=False,
|
||||
widget=forms.PasswordInput(render_value=False))
|
||||
tenant_id = forms.ChoiceField(label=_("Primary Project"))
|
||||
|
||||
|
@ -82,10 +82,25 @@ class UsersViewTests(test.BaseAdminViewTests):
|
||||
'confirm_password': "doesntmatch"}
|
||||
|
||||
res = self.client.post(USER_CREATE_URL, formData)
|
||||
self.assertFormError(res,
|
||||
"form",
|
||||
None,
|
||||
['Passwords do not match.'])
|
||||
self.assertFormError(res, "form", None, ['Passwords do not match.'])
|
||||
|
||||
def test_user_password_validation(self):
|
||||
user = self.users.get(id="1")
|
||||
self.mox.StubOutWithMock(api, 'tenant_list')
|
||||
api.tenant_list(IgnoreArg(), admin=True).AndReturn(self.tenants.list())
|
||||
self.mox.ReplayAll()
|
||||
|
||||
formData = {'method': 'CreateUserForm',
|
||||
'name': user.name,
|
||||
'email': user.email,
|
||||
'password': 'four',
|
||||
'tenant_id': self.tenant.id,
|
||||
'confirm_password': "four"}
|
||||
|
||||
res = self.client.post(USER_CREATE_URL, formData)
|
||||
self.assertFormError(
|
||||
res, "form", 'password',
|
||||
['Your password must be at least 6 characters long.'])
|
||||
|
||||
def test_enable_user(self):
|
||||
user = self.users.get(id="2")
|
||||
|
@ -89,6 +89,10 @@ SESSION_ENGINE = 'django.contrib.sessions.backends.cache'
|
||||
HORIZON_CONFIG = {
|
||||
'dashboards': ('nova', 'syspanel', 'settings',),
|
||||
'default_dashboard': 'nova',
|
||||
"password_validator": {
|
||||
"regex": '.{6,}',
|
||||
"help_text": "Your password must be at least 6 characters long."
|
||||
},
|
||||
}
|
||||
|
||||
AVAILABLE_REGIONS = [
|
||||
|
@ -16,6 +16,8 @@
|
||||
|
||||
import re
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
from django.core import validators
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
@ -31,3 +33,15 @@ validate_ipv4_cidr = validators.RegexValidator(ipv4_cidr_re)
|
||||
def validate_port_range(port):
|
||||
if port not in range(-1, 65535):
|
||||
raise ValidationError("Not a valid port number")
|
||||
|
||||
|
||||
def password_validator():
|
||||
config = getattr(settings, "HORIZON_CONFIG", {})
|
||||
password_config = config.get("password_validator", {})
|
||||
return password_config.get("regex", ".*")
|
||||
|
||||
|
||||
def password_validator_msg():
|
||||
config = getattr(settings, "HORIZON_CONFIG", {})
|
||||
password_config = config.get("password_validator", {})
|
||||
return password_config.get("help_text", None)
|
||||
|
@ -1,5 +1,7 @@
|
||||
import os
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
DEBUG = True
|
||||
TEMPLATE_DEBUG = DEBUG
|
||||
PROD = False
|
||||
@ -8,6 +10,14 @@ USE_SSL = False
|
||||
# Note: You should change this value
|
||||
SECRET_KEY = 'elj1IWiLoWHgcyYxFVLj7cM5rGOOxWl0'
|
||||
|
||||
# Specify a regular expression to validate user passwords.
|
||||
# HORIZON_CONFIG = {
|
||||
# "password_validator": {
|
||||
# "regex": '.*',
|
||||
# "help_text": _("Your password does not meet the requirements.")
|
||||
# }
|
||||
# }
|
||||
|
||||
LOCAL_PATH = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
# We recommend you use memcached for development; otherwise after every reload
|
||||
|
Loading…
x
Reference in New Issue
Block a user