diff --git a/location_app/app/functions/auth/base.py b/location_app/app/functions/auth/base.py index 3cb3d1f..fb7f38d 100644 --- a/location_app/app/functions/auth/base.py +++ b/location_app/app/functions/auth/base.py @@ -81,7 +81,8 @@ def check_month(month, day): return True else: return False - elif month == 2: # February + #February + elif month == 2: if (day > 0 and day <= 28): return True else: diff --git a/location_app/app/functions/auth/change_password.py b/location_app/app/functions/auth/change_password.py index 0859cc3..90bf1db 100644 --- a/location_app/app/functions/auth/change_password.py +++ b/location_app/app/functions/auth/change_password.py @@ -1,5 +1,6 @@ import sqlite3 as sql from app.functions.auth import base +import re database_user = "app/databases/users.db" @@ -17,7 +18,6 @@ def change_password(data): update_password(data) return _status - def check_pass_data(data): """ Compares dates of birth and if the new passwords match, @@ -31,13 +31,14 @@ def check_pass_data(data): return "wrong_date" if not (data['password'] == data['r_password']): return "pass_no_match" + pass_status = is_pass_valid(data['password']) + if pass_status != "ok": + return pass_status return "success" return "no_id" else: return _status - - def check_empty(data): """ Checks if all the fields in the dictionary are filled, @@ -58,7 +59,25 @@ def check_empty(data): else: return "ok" - +def is_pass_valid(password): + """ + Checks if the user inputted password matches all + the criteria + """ + if len(password) < 5: + return "too_short" + elif len(password) > 15: + return "too_long" + elif not re.search("[A-Z]", password): + return "no_up" + elif not re.search("[a-z]", password): + return "no_low" + elif not re.search("[0-9]", password): + return "no_num" + elif not re.search("[^a-zA-Z0-9_]", password): + return "no_sym" + else: + return "ok" def update_password(data): """ diff --git a/location_app/app/functions/auth/create_profile.py b/location_app/app/functions/auth/create_profile.py index 08a0a6a..4b8bb39 100644 --- a/location_app/app/functions/auth/create_profile.py +++ b/location_app/app/functions/auth/create_profile.py @@ -1,6 +1,6 @@ import sqlite3 as sql from app.functions.auth import base - +import re database_user = "app/databases/users.db" @@ -17,7 +17,6 @@ def create_profile(data): if _status == "success": make_user(data) return _status - def check_prof_data(data): """ @@ -31,6 +30,9 @@ def check_prof_data(data): if not base.user_exists(data['username']): if not (data['password'] == data['r_password']): return "pass_no_match" + pass_status = is_pass_valid(data['password']) + if pass_status != "ok": + return pass_status elif not base.check_date(data['day'], data['month'], data['year']): @@ -43,7 +45,6 @@ def check_prof_data(data): return "no_id" return _status - def check_empty(data): """ Checks if all the fields in the dictionary are filled, @@ -68,7 +69,25 @@ def check_empty(data): else: return "ok" - +def is_pass_valid(password): + """ + Checks if the user inputted password matches all + the criteria + """ + if len(password) < 5: + return "too_short" + elif len(password) > 15: + return "too_long" + elif not re.search("[A-Z]", password): + return "no_up" + elif not re.search("[a-z]", password): + return "no_low" + elif not re.search("[0-9]", password): + return "no_num" + elif not re.search("[^a-zA-Z0-9_]", password): + return "no_sym" + else: + return "ok" def make_user(data): """ diff --git a/location_app/app/functions/auth/login.py b/location_app/app/functions/auth/login.py index da1a38e..846bc6b 100644 --- a/location_app/app/functions/auth/login.py +++ b/location_app/app/functions/auth/login.py @@ -12,8 +12,6 @@ def login(data): _status = check_login_data(data) return _status - - def check_login_data(data): """ Checks the validity of inputed data, if @@ -33,7 +31,6 @@ def check_login_data(data): return "success" else: return _status - def check_empty(data): """ diff --git a/location_app/app/templates/login/create.html b/location_app/app/templates/login/create.html index 6c40f4b..db67bc4 100644 --- a/location_app/app/templates/login/create.html +++ b/location_app/app/templates/login/create.html @@ -87,6 +87,18 @@ {% if status == 'empty_pass' %}

Empty Password

+ {% elif status == 'no_low' %} +

Password should contain atleast 1 lowercase letter

+ {% elif status == 'no_up' %} +

Password should contain atleast 1 uppercase letter

+ {% elif status == 'no_num' %} +

Password should contain atleast 1 number

+ {% elif status == 'no_sym' %} +

Password should contain atleast 1 symbol

+ {% elif status == 'too_short' %} +

Password is too short

+ {% elif status == 'too_long' %} +

Password is too long

{% endif %}
diff --git a/location_app/app/templates/login/forgot.html b/location_app/app/templates/login/forgot.html index 3306cb6..7c7184b 100644 --- a/location_app/app/templates/login/forgot.html +++ b/location_app/app/templates/login/forgot.html @@ -69,6 +69,18 @@ {% if status == 'empty_pass' %}

Empty Password

+ {% elif status == 'no_low' %} +

Password should contain atleast 1 lowercase letter

+ {% elif status == 'no_up' %} +

Password should contain atleast 1 uppercase letter

+ {% elif status == 'no_num' %} +

Password should contain atleast 1 number

+ {% elif status == 'no_sym' %} +

Password should contain atleast 1 symbol

+ {% elif status == 'too_short' %} +

Password is too short

+ {% elif status == 'too_long' %} +

Password is too long

{% endif %}