Skip to content

Commit 5358ea9

Browse files
uds5501abhinavk96
authored andcommitted
Changing min pass length from 4 to 8 (fossasia#5599)
* 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 <[email protected]>
1 parent 5adcbc1 commit 5358ea9

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

Diff for: app/api/auth.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,9 @@ def change_password():
251251
return NotFoundError({'source': ''}, 'User Not Found').respond()
252252
else:
253253
if user.is_correct_password(old_password):
254-
254+
if len(new_password) < 8:
255+
return BadRequestError({'source': ''},
256+
'Password should have minimum 8 characters').respond()
255257
user.password = new_password
256258
save_to_db(user)
257259
send_email_with_action(user, PASSWORD_CHANGE,

Diff for: app/api/users.py

+4
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,14 @@ class UserList(ResourceList):
4141
def before_create_object(self, data, view_kwargs):
4242
"""
4343
method to check if there is an existing user with same email which is received in data to create a new user
44+
and if the password is at least 8 characters long
4445
:param data:
4546
:param view_kwargs:
4647
:return:
4748
"""
49+
if len(data['password']) < 8:
50+
raise UnprocessableEntity({'source': '/data/attributes/password'},
51+
'Password should be at least 8 characters long')
4852
if db.session.query(User.id).filter_by(email=data['email']).scalar() is not None:
4953
raise ConflictException({'pointer': '/data/attributes/email'}, "Email already exists")
5054

Diff for: create_db.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ def create_default_user(email, password):
2424
ask_password = True
2525
while ask_password:
2626
password = getpass.getpass("Enter password for super_admin : ")
27-
if len(password) < 4:
28-
print('\nPassword should have minimum 4 characters')
27+
if len(password) < 8:
28+
print('\nPassword should have minimum 8 characters')
2929
continue
3030
repassword = getpass.getpass("Enter your password again to confirm : ")
3131
if password != repassword:

0 commit comments

Comments
 (0)