Skip to content

Commit

Permalink
Settings names and messages fix
Browse files Browse the repository at this point in the history
  • Loading branch information
blagojabozinovski committed Aug 22, 2023
1 parent 2138bb7 commit 0fe4a83
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ To install ckanext-password-policy:

```
Minimum length of the user password. Default is 12
ckan.password_policy.password_length = 12
ckanext.password_policy.password_length = 12

Number of failed logins before the user is locked. Default is 3
ckan.password_policy.failed_logins = 3
ckanext.password_policy.failed_logins = 3

Time after the locked user is allowed to log in again in seconds. Default is 600
ckan.password_policy.user_locked_time = 600
ckanext.password_policy.user_locked_time = 600
```


Expand Down
4 changes: 2 additions & 2 deletions ckanext/password_policy/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def user_login_count(username):
redis_conn = connect_to_redis()
user_cached = redis_conn.get(username)
if user_cached == None:
expiry = config.get('ckan.password_policy.user_locked_time', 600)
expiry = config.get('ckanext.password_policy.user_locked_time', 600)
# user will be cached in redis with count 1
redis_conn.set(username, 1, ex=expiry)
else:
Expand Down Expand Up @@ -38,7 +38,7 @@ def custom_password_check(password):
1 uppercase letter or more
1 lowercase letter or more
"""
password_length = int(config.get('ckan.password_policy.password_length', 12))
password_length = int(config.get('ckanext.password_policy.password_length', 12))
# calculating the length
length_error = len(password) < password_length

Expand Down
6 changes: 2 additions & 4 deletions ckanext/password_policy/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
Missing = df.Missing
missing = df.missing

password_length = config.get('ckan.password_policy.password_length')
password_length = int(config.get('ckanext.password_policy.password_length', 12))


def user_custom_password_validator(key, data, errors, context):
Expand All @@ -24,9 +24,7 @@ def user_custom_password_validator(key, data, errors, context):
elif value == '':
pass
elif not valid_pass['password_ok']:
errors[('password',)].append(_(f'Your password must be {password_length} characters or '
'longer and contain uppercase, lowercase, '
'digit and special character'))
errors[('password',)].append('Your password must be 12 characters or longer and contain uppercase, lowercase, digit and special character')


class PasswordPolicyPlugin(plugins.SingletonPlugin):
Expand Down
8 changes: 3 additions & 5 deletions ckanext/password_policy/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,12 @@ def _get_form_password(self):
password1 = request.form.get(u'password1')
password2 = request.form.get(u'password2')

password_length = config.get('ckan.password_policy.password_length')
password_length = int(config.get('ckanext.password_policy.password_length', 12))

valid_pass = helper.custom_password_check(password1)
if valid_pass['password_ok']==False:
raise ValueError(
_(f"u'Your password must be {password_length} characters or '"
u'longer and contain uppercase, lowercase, '
u'digit and special character'))
_(f'Your password must be 12 characters or longer and contain uppercase, lowercase, digit and special character'))
elif password1 != password2:
raise ValueError(
_(u'The passwords you entered'
Expand All @@ -128,7 +126,7 @@ def identify(self, environ):
the ``environ``.
'''
allowed_failes_logins = int(config.get('ckan.password_policy.failed_logins', 3))
allowed_failes_logins = int(config.get('ckanext.password_policy.failed_logins', 3))
request = Request(environ, charset=self.charset)

path_info = environ[u'PATH_INFO']
Expand Down

0 comments on commit 0fe4a83

Please sign in to comment.