Skip to content

Commit

Permalink
Changing min pass length from 4 to 8 (#5599)
Browse files Browse the repository at this point in the history
* Changing min pass length from 4 to 6

* Updating pass restriction from 6 to 8

- Adding password length checker in API

* Adding minimum length check in change-password


Co-authored-by: Abhinav Khare <abhinav.khare31@gmail.com>
  • Loading branch information
2 people authored and iamareebjamal committed Feb 13, 2019
1 parent 5adcbc1 commit 5358ea9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion app/api/auth.py
Expand Up @@ -251,7 +251,9 @@ def change_password():
return NotFoundError({'source': ''}, 'User Not Found').respond()
else:
if user.is_correct_password(old_password):

if len(new_password) < 8:
return BadRequestError({'source': ''},
'Password should have minimum 8 characters').respond()
user.password = new_password
save_to_db(user)
send_email_with_action(user, PASSWORD_CHANGE,
Expand Down
4 changes: 4 additions & 0 deletions app/api/users.py
Expand Up @@ -41,10 +41,14 @@ class UserList(ResourceList):
def before_create_object(self, data, view_kwargs):
"""
method to check if there is an existing user with same email which is received in data to create a new user
and if the password is at least 8 characters long
:param data:
:param view_kwargs:
:return:
"""
if len(data['password']) < 8:
raise UnprocessableEntity({'source': '/data/attributes/password'},
'Password should be at least 8 characters long')
if db.session.query(User.id).filter_by(email=data['email']).scalar() is not None:
raise ConflictException({'pointer': '/data/attributes/email'}, "Email already exists")

Expand Down
4 changes: 2 additions & 2 deletions create_db.py
Expand Up @@ -24,8 +24,8 @@ def create_default_user(email, password):
ask_password = True
while ask_password:
password = getpass.getpass("Enter password for super_admin : ")
if len(password) < 4:
print('\nPassword should have minimum 4 characters')
if len(password) < 8:
print('\nPassword should have minimum 8 characters')
continue
repassword = getpass.getpass("Enter your password again to confirm : ")
if password != repassword:
Expand Down

0 comments on commit 5358ea9

Please sign in to comment.